View previous topic :: View next topic |
Author |
Message |
oz_tiram n00b
Joined: 31 May 2015 Posts: 45
|
Posted: Mon Nov 27, 2023 11:31 am Post subject: Building a go program with static linking |
|
|
Hi!
I am trying to compile a go program in gentoo using the following flags:
Code: | export CGO_LDFLAGS="-static -Wl,--fatal-warnings"
CGO_ENABLED=1 go build -o build/fail-over-agent cmd/fail-over-agent/main.go |
But I am seeing the following error:
Code: | # command-line-arguments
/usr/lib/go/pkg/tool/linux_amd64/link: running x86_64-pc-linux-gnu-gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000021.o: in function `mygetgrouplist':
/_/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000020.o: in function `mygetgrgid_r':
/_/os/user/cgo_lookup_cgo.go:45: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000020.o: in function `mygetgrnam_r':
/_/os/user/cgo_lookup_cgo.go:54: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000020.o: in function `mygetpwnam_r':
/_/os/user/cgo_lookup_cgo.go:36: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000020.o: in function `mygetpwuid_r':
/_/os/user/cgo_lookup_cgo.go:27: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/go-link-2673223290/000004.o: in function `_cgo_cbcce81e6342_C2func_getaddrinfo':
/tmp/go-build/cgo_unix_cgo.cgo2.c:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
|
From googling around, it seemed that recompiling glibc with static-libs enabled should solve the issue , but it's not.
I have added static-libs to /etc/portage/make.conf and re-built glibc.
(It seems this the default btw)
Any idea how to overcome this error? |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9625 Location: beyond the rim
|
Posted: Mon Nov 27, 2023 3:32 pm Post subject: |
|
|
Do you actually need to use cgo for building? If not just try
Code: | CGO_ENABLED=0 go build ... |
Also not seeing any actual error in the output other than the summary, only warnings. The warnings all relate to functions using NSS which uses dynamically loaded plugins using dlopen, which can cause problems when using static linking. If you don't know what NSS is, you probably won't need it (and therefore also won't need cgo). |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 23066
|
Posted: Mon Nov 27, 2023 4:04 pm Post subject: Re: Building a go program with static linking |
|
|
oz_tiram wrote: | I have added static-libs to /etc/portage/make.conf and re-built glibc.
(It seems this the default btw) | This is not correct, in multiple ways. First, you rarely need or want USE=static-libs, so you should use package.use to set it only on those packages where you cannot avoid it. Second, USE=static-libs is not the default on any standard Gentoo profile I know of. Third, I think enabling glibc static libraries is not the right way to resolve the shown warning. |
|
Back to top |
|
|
|