英文:
C source files not allowed when not using cgo or SWIG
问题
我正在使用Go 1.6在OSX 10.11.4上,并尝试将我的Go程序交叉编译为Windows和Linux。我在我的Go程序中使用了一个库(https://github.com/pebbe/zmq4),它是一个基于C的实现的Go绑定。我按照这里列出的指示进行了交叉编译为x86 Windows,使用了以下命令:
env GOOS=windows GOARCH=386 go build -v znode.go
然而,上述命令给我返回了以下错误:
znode.go:15:2: 当不使用cgo或SWIG时,不允许使用C源文件:dummy.c
有没有解决这个问题的方法?我在stackoverflow上看到其他帖子建议使用go1.5,但我已经在使用go1.6了。
英文:
I am using Go 1.6 on OSX 10.11.4 and trying to cross compile my go program for windows and linux. I use a library (https://github.com/pebbe/zmq4) in my go program which is a Go binding for a C based implementation. I followed the instructions to cross compile for x86 windows as listed here by issuing the following command:
env GOOS=windows GOARCH=386 go build -v znode.go
However the above command gives me the following error
znode.go:15:2: C source files not allowed when not using cgo or SWIG: dummy.c
Is there a workaround for this? I saw other posts on stackoverflow which suggest moving to go1.5 but i am already on go1.6
答案1
得分: 2
FWIW(For What It's Worth),在六年后... user720694的评论给出了线索。如果在构建目录中存在任何.c或.cpp/cc等文件,在执行go build
之前添加CGO_ENABLED=0
可以解决问题。
英文:
FWIW after six years ... user720694's comment has the clue. If there are any .c or .cpp/cc/etc. files in the build directory, adding CGO_ENABLED=0
before go build
does the trick.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论