标签:动态库 静态 参数 .so std question bin lin may
go build -buildmode=c-shared -o libgobblob.so
命令执行之后,会生成libgobblob.h和 libgobblob.so
windows需要安装gcc编译器,我用的的MinGW包,解压,把bin目录加入环境变量。
然后执行命令之后发现会报错,windows下go不支持生成动态库。
>>go build -buildmode=c-shared -o libgobblob.dll
-buildmode=c-shared not supported on windows/amd64
这一步折腾了好久,最终在stackoverflow找到了解决方法。[[ https://stackoverflow.com/questions/40573401/building-a-dll-with-go-1-7 | building-a-dll-with-go]]
go build -buildmode=c-archive -o libgobblob.a
#include <stdio.h>
#include "libgobblob.h"
// force gcc to link in go runtime (may be a better solution than this)
void dummy() {
// 所有在go中要导出的代码都在这里调用一次,参数随便写,只要能编译ok即可
gobblob_init(NULL,NULL,NULL);
gobblob_deinit(NULL);
gobblob(NULL,NULL,NULL,NULL,NULL,NULL);
}
int main() {
}
执行如下命令,生成dll
gcc -shared -pthread -o libgobblob.dll gobblob.c libgobblob.a -lWinMM -lntdll -lWS2_32 -Iinclude
标签:动态库 静态 参数 .so std question bin lin may
原文地址:http://www.cnblogs.com/fitness/p/8004494.html