Help with gccgo cross compiler static linking

441 views
Skip to first unread message

andrewc...@gmail.com

unread,
May 26, 2015, 1:01:31 AM5/26/15
to golan...@googlegroups.com
Can gccgo cross compile fully static binaries? I can't seem to stop it from dynamically linking glibc.

mipsel-linux-go  build -gccgoflags="-static"
/home/andrewc/Desktop/mips/cross/output/lib/gcc/mipsel-linux/5.1.0/../../../../mipsel-linux/lib/libgo.a(user.o): In function `user.lookupUnix':
/home/andrewc/Desktop/mips/cross/build-gcc/mipsel-linux/libgo/../../../gcc/libgo/go/os/user/lookup_unix.go:67: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/andrewc/Desktop/mips/cross/build-gcc/mipsel-linux/libgo/../../../gcc/libgo/go/os/user/lookup_unix.go:81: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/andrewc/Desktop/mips/cross/output/lib/gcc/mipsel-linux/5.1.0/../../../../mipsel-linux/lib/libgo.a(net.o): In function `net.cgoLookupPort':
/home/andrewc/Desktop/mips/cross/build-gcc/mipsel-linux/libgo/../../../gcc/libgo/go/net/cgo_unix.go:83: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Ian Lance Taylor

unread,
May 26, 2015, 9:54:58 AM5/26/15
to Andrew Chambers, golang-nuts
This is not a gccgo issue. It's a glibc issue. If you look at the
resulting executable, it should be statically linked. However, as the
warning indicates, if you want to actually run the executable, it must
be able to find, at runtime, the dynamic libraries from the same glibc
version. Glibc requires this for any program that looks up user or
host information.

I haven't tried this, but you can apparently avoid this by rebuilding
glibc itself, which is not a task recommended for beginners:

https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked_programs_need_some_shared_libraries_which_is_not_acceptable_for_me.__What_can_I_do.3F

Ian

andrewc...@gmail.com

unread,
May 26, 2015, 6:38:55 PM5/26/15
to golan...@googlegroups.com, andrewc...@gmail.com
Thanks, perhaps I can avoid this by building gcc newlib instead of glibc. I am trying to produce entirely static binaries for running on a router even if the libc version etc may change.
Reply all
Reply to author
Forward
0 new messages