即将发布的 Go 1.5 带有新的构建模式,允许导出要从 C 代码链接和调用的 Go 符号。我一直在玩它,并获得了基本的“Hello world”示例,但现在我正在尝试链接一个 Go 库,它启动了 anet/http.Server并且它失败了。代码如下所示(也可在此处获得):gohttplib.go:package mainimport "C"import "net/http"//export ListenAndServefunc ListenAndServe(caddr *C.char) { addr := C.GoString(caddr) http.ListenAndServe(addr, nil)}func main() {}示例/c/main.c:#include <stdio.h>#include "../../gohttplib.h"int main(){ ListenAndServe(":8000"); return 0;}生成静态链接的对象和标题工作正常:$ go build -buildmode=c-archive但是针对它进行编译失败了:$ gcc -o gohttp-c examples/c/main.c gohttplib.a -lpthreadUndefined symbols for architecture x86_64: "_CFArrayGetCount", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) "_CFArrayGetValueAtIndex", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) "_CFDataAppendBytes", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) "_CFDataCreateMutable", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) "_CFDataGetBytePtr", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) __cgo_6dbb806e9976_Cfunc_CFDataGetBytePtr in gohttplib.a(000003.o) (maybe you meant: __cgo_6dbb806e9976_Cfunc_CFDataGetBytePtr) "_CFDataGetLength", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) __cgo_6dbb806e9976_Cfunc_CFDataGetLength in gohttplib.a(000003.o) (maybe you meant: __cgo_6dbb806e9976_Cfunc_CFDataGetLength) "_CFRelease", referenced from: _FetchPEMRoots in gohttplib.a(000003.o) __cgo_6dbb806e9976_Cfunc_CFRelease in gohttplib.a(000003.o) (maybe you meant: __cgo_6dbb806e9976_Cfunc_CFRelease)这是在 OS X 10.9.5 上使用 Go github 存储库 (38e3427) 中的最新版本。我知道 Go 1.5 还没有发布,并且不能保证它可以工作,但我这样做是出于教育目的,我怀疑我遗漏了一些东西。
1 回答
- 1 回答
- 0 关注
- 299 浏览
添加回答
举报
0/150
提交
取消