【笔记】【GO语言】Go调用C共享库

//LibHelloWorld.h
void SayHelloWorld(char * name);

//HelloWorld.c
#include <stdio.h>
#include "LibHelloWorld.h"
void SayHelloWorld(char * name){
    printf("Hello,%s!\n",name);
}

gcc -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"HelloWorld.d" -MT"HelloWorld.d" -o"HelloWorld.o" "../HelloWorld.c"
gcc -shared -o"libLibHelloWorld.so" ./HelloWorld.o

//myCGO.go

package main 

/*
#cgo LDFLAGS: -L./ -lLibHelloWorld
#include "LibHelloWorld.h"
*/
import (
    "C"
)

func main() {
    C.SayHelloWorld(C.CString("Azik"))
}

OK!Finish!

posted @ 2013-11-17 09:38  Azik  阅读(563)  评论(0编辑  收藏  举报