cgo的交叉编译(针对darwin)失败了。

huangapple go评论82阅读模式
英文:

Cross-compilation of cgo (for darwin) fails

问题

我对Go和Linux都比较新手。

我在Linux环境下构建了一个应用程序,该应用程序使用了基于cgo的gtk库(https://github.com/mattn/go-gtk/)。该应用程序在其本机环境(Linux 64位)中构建正常,但是当我尝试为darwin 64位编译时,出现以下结果:

# net
无法确定C.AI_MASK的名称类型
# net
无法确定C.AI_MASK的名称类型

我用于构建的命令行:

env GOOS=$1 GOARCH=$2 CGO_ENABLED=1 go build $3

其中$1是darwin,$2是amd64($3是我的应用程序路径)。

由于错误似乎来自我导入的库,我不确定该怎么修复它。我还读到过关于交叉编译cgo不起作用的说法,因为它依赖于本机的macOS内容,所以需要在Mac上构建。这是真的吗?还是有什么方法可以使其在我的环境中工作?

我也有点困惑,因为似乎大多数讨论这个主题的人都在谈论Go 1.5之前的版本,如果我理解正确的话,那个版本在交叉编译方面完全不同。

谢谢。

英文:

I am fairly new to go and even Linux in general.

I have built an app in a Linux environment which makes use of a gtk lib based on cgo (https://github.com/mattn/go-gtk/). The application builds fine in its native environment (linux 64bit) but when I try to compile for darwin 64bit I get the following result:

# net
could not determine kind of name for C.AI_MASK
# net
could not determine kind of name for C.AI_MASK

The command line I use to build:

env GOOS=$1 GOARCH=$2 CGO_ENABLED=1 go build $3

Where $1 is darwin and $2 amd64 (and $3 the path to my app).

As the error seems to come from the lib I import, I am not sure what to do to fix it. I have also read that cross compiling cgo does not really work as it relies on native macos stuff so it would need to be built on a mac. Is this true or is there something I can do to make it work in my environment?

I am also slightly confused as it seems most people discussing this subject are talking of go pre 1.5 which was entirely different when it comes to cross-compiling if I understand correctly.

Thanks

答案1

得分: 6

我现在能够成功地在Linux上为Darwin编译我的代码,这要归功于JimB的评论。

我所需要的是一个OSX工具链,比如github.com/tpoechtrager/osxcross

然后,我通过执行以下命令来编译我的代码:env OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1 MACOSX_DEPLOYMENT_TARGET=10.6 CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -v mywork/myprogram

我的一些程序成功编译,一些在链接时抛出错误,但我想那是另一个问题,所以我将把这个问题标记为已解决,至于交叉编译方面。

英文:

I am now able to compile successfully my code on linux for darwin thanks to the comments by JimB.

What I needed was a osx toolchain such as github.com/tpoechtrager/osxcross.

Then I compiled my code by doing env OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1 MACOSX_DEPLOYMENT_TARGET=10.6 CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -v mywork/myprogram.

Some of my programs compile successfully, some throw errors at linking time but I guess that's another issue so I'll mark this question as solved as far as the cross-compilation goes.

huangapple
  • 本文由 发表于 2015年12月4日 17:12:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/34084597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定