I am trying to compile some cgo code for Solaris. I get these errors when I try to build:
$ CGO_LDFLAGS="-L$(pwd)/solaris-11.4-amd64-libs" CGO_CFLAGS='-I/home/shane/src/ioctl-experimentation/solaris-11.4-headers -Wno-unknown-pragmas' CGO_ENABLED=1 GOOS=solaris GOARCH=amd64 go build # runtime/cgo /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x16): undefined reference to `__libc_csu_fini' /usr/bin/ld: (.text+0x1d): undefined reference to `__libc_csu_init' /usr/bin/ld: (.text+0x2a): undefined reference to `__libc_start_main' /usr/bin/ld: $WORK/b003/_x003.o: in function `_cgo_release_context': gcc_context.c:(.text+0x5c): undefined reference to `__stack_chk_fail' /usr/bin/ld: $WORK/b003/_x004.o: in function `x_cgo_sys_thread_create': gcc_libinit.c:(.text+0x87): undefined reference to `__stack_chk_fail' /usr/bin/ld: $WORK/b003/_x004.o: in function `_cgo_wait_runtime_init_done': gcc_libinit.c:(.text+0x121): undefined reference to `__stack_chk_fail' /usr/bin/ld: $WORK/b003/_x004.o: in function `_cgo_try_pthread_create': gcc_libinit.c:(.text+0x291): undefined reference to `__stack_chk_fail' /usr/bin/ld: $WORK/b003/_x006.o: in function `x_cgo_init': gcc_solaris_amd64.c:(.text+0xb6): undefined reference to `__stack_chk_fail' /usr/bin/ld: $WORK/b003/_x006.o:gcc_solaris_amd64.c:(.text+0x214): more undefined references to `__stack_chk_fail' follow collect2: error: ld returned 1 exit status
I am cross-compiling on Linux. Here is my Go version:
$ go version go version go1.18.3 linux/amd64
The solaris-11.4-amd64-libs
directory contains a copy of all files under /lib/amd64
from a Solaris 11.4 AMD64 machine. The solaris-11.4-headers
directory contains a copy of all files under /usr/include
from a Solaris 11.4 AMD64 machine.
Here is my Go code in main.go
:
//go:build solaris
// +build solaris
package main
import "C"
func main() {
}
I know cgo is fully supported for Solaris as of Go 1.5, and I am using Go 1.18.
I'm looking for help understanding why these linker errors are happening, even when I copied across all libs from the /lib/amd64
directory. Is it possible there are more libs I also need to copy over from somewhere else?
Edit
At the suggestion of Liam Kelly, I looked at this question about how to link against a different libc. I tried passing -Xlinker -rpath=$(pwd)/solaris-11.4-amd64-libs
as part of CGO_LDFLAGS
, but I got the same errors as before. I tried using -nodefaultlibs
and -nostdlib
both separately and together along with -Xlinker -rpath=$(pwd)/solaris-11.4-amd64-libs
, but using either of these two flags either separately or together just increased the number of linker errors.