cpjolicoeur
cpjolicoeur

Reputation: 13106

Cross compile CGO app on darwin for linux

I'm having issues trying to cross-compile a Go app on OS X to run on linux/amd64. The app in question is using libvips via this vips go package. As such, it is using CGO and needs to be compiled with CGO support.

I'm on Go 1.4 and running the following build command

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build

but end up with a linker error

ld: unknown option: --build-id=none clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm assuming I probably need to add some kind of -ldflags argument but am not sure.

Is it possible to cross-compile CGO apps in this manner yet, or do I need to do a native-build on the target system to avoid issues and headaches?

Upvotes: 4

Views: 3232

Answers (2)

dh1tw
dh1tw

Reputation: 1491

Fast-forwarding to 2022, using docker for cross-compiling CGO apps to other platforms is your best and cleanest choice. Build docker containers that contain the correct cross-platform compiler and C libraries. Here is how I cross-compile my Cgo applications with Docker. Here is the repo with the dockerfiles.

Upvotes: 0

simonmenke
simonmenke

Reputation: 2880

Have a look at gonative. this allows you to cross-compile cgo code (as long as you are just using the stdlib).

Another approach would be to compile the linux binary using docker.

Upvotes: 1

Related Questions