cross compile cgo get ld: symbol(s) not found for architecture x86_64 error

171 views
Skip to first unread message

Guang Chen

unread,
Nov 3, 2014, 8:23:17 AM11/3/14
to golan...@googlegroups.com
I try to cross compile a program on darwin to linux with cgo enabled, the code can be found on https://gist.github.com/cgcgbcbc/bebc102695aa80dd99e1 . 
When I use CGO_ENABLED=1 GOOS=linux go build for building, clang says:

# lis

ld: warning: ignoring file /var/folders/z_/p019fgdx4k1831q1gv7xq95w0000gn/T//go-link-IQyUY5/go.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /var/folders/z_/p019fgdx4k1831q1gv7xq95w0000gn/T//go-link-IQyUY5/go.o

Undefined symbols for architecture x86_64:

  "_main", referenced from:

     implicit entry/start for main executable

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

/usr/local/Cellar/go/1.3.3/libexec/pkg/tool/darwin_amd64/6l: running clang failed: unsuccessful exit status 0x100

Ian Taylor

unread,
Nov 3, 2014, 9:47:10 AM11/3/14
to Guang Chen, golang-nuts
If you want to cross-compile a Go program that uses cgo, then you must
also have a C cross-compiler. When you run the go command, set the CC
environment variable to that cross-compiler.

Ian
Reply all
Reply to author
Forward
0 new messages