Building a Linux shared library on Mac OS, expected to work?

598 views
Skip to first unread message

aar...@arista.com

unread,
Aug 13, 2015, 1:51:22 PM8/13/15
to golang-nuts
Hello,

I am having trouble building a linux .so on my Mac (10.10.4) with go1.5rc1.

I have tried doing it and seem to be running into two errors:

$ GOOS=linux go build -buildmode=shared -ldflags=-v std
# /var/folders/dh/8tf0gx091zs_02mw_s0c956w0000gp/T/go-build640930786/libstd.so
HEADER = -H5 -T0x401000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime/cgo.a in $WORK/runtime/cgo.a
searching for runtime/cgo.a in /usr/local/go/pkg/linux_amd64_dynlink/runtime/cgo.a
warning: unable to find runtime/cgo.a
 0.00 deadcode
 0.08 pclntab=2197275 bytes, funcdata total 528908 bytes
 0.11 dodata
 0.33 reloc
 0.39 asmb
 0.39 codeblk
 0.62 datblk
 0.63 sym
 0.66 symsize = 1321632
 0.70 symsize = 2417832
 0.70 dwarf
 0.93 symsize = 2417832
 1.49 dwarf pass 2.
 2.12 headr
host link: "clang" "-m64" "-gdwarf-2" "-Wl,-Bsymbolic-functions" "-shared" "-o" "/var/folders/dh/8tf0gx091zs_02mw_s0c956w0000gp/T/go-build640930786/libstd.so" "-rdynamic" "-Qunused-arguments" "/var/folders/dh/8tf0gx091zs_02mw_s0c956w0000gp/T/go-link-714171355/000000.o" "/var/folders/dh/8tf0gx091zs_02mw_s0c956w0000gp/T/go-link-714171355/go.o"
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -Bsymbolic-functions
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not sure if this is related, but building go from source is failing when running the cgo/testcshared test:
##### ../misc/cgo/testso

##### ../misc/cgo/testsovar

##### ../misc/cgo/testcarchive
PASS
PASS
PASS

##### ../misc/cgo/testcshared
FAIL test2 got
2015/08/13 10:16:02 Failed: exit status 1

Thanks for your help,
Aaron

Ian Lance Taylor

unread,
Aug 13, 2015, 3:01:15 PM8/13/15
to aar...@arista.com, golang-nuts
Building a shared library requires a C compiler. In your case, it
requires a Darwin -> GNU/Linux cross-compiler. If you have that, set
the CC environment variable to point to it.

Ian

gla...@meteor.com

unread,
Aug 30, 2015, 2:33:57 PM8/30/15
to golang-nuts, aar...@arista.com
On Thursday, August 13, 2015 at 12:01:15 PM UTC-7, Ian Lance Taylor wrote:
> Building a shared library requires a C compiler.  In your case, it 
> requires a Darwin -> GNU/Linux cross-compiler.  If you have that, set 
> the CC environment variable to point to it. 

Does anyone know what a good value for this is on OS X?  `./all.bash` fails for me on a clean checkout with this same failure otherwise (and I don't know how to choose to ignore this error if I wanted to continue my build without this test).

Ian Lance Taylor

unread,
Aug 30, 2015, 2:42:57 PM8/30/15
to gla...@meteor.com, golang-nuts, Aaron Beitch
This discussion about cross-compiling from Darwin to GNU/Linux. Using
all.bash when cross-compiling requires extra care because the builds
generate programs that do not run on the build system.

If you are not cross-compiling, then please start a new thread about
the problem you are having. Thanks.

Ian
Reply all
Reply to author
Forward
0 new messages