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 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理