dousong1992 2015-12-04 09:12
浏览 226
已采纳

交叉编译CGO(对于Darwin)失败

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条回答 默认 最新

  • dongwupei7803 2015-12-29 08:01
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?