【笔记】【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 @   Azik  阅读(563)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示