How to cross compile a Go program and still retain the dynamic linked to libc?
Context: The compiling host is macOS M1, target is Linux amd64. The default
result is static linked. However I still want to have dynamic linked, esp for libc part to have LD_PRELOAD ability).
Trying to force dynamic linked like this
❯ CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -o main cmd/server/main.go
# runtime/cgo
linux_syscall.c:67:13: error: call to undeclared function 'setresgid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: call to undeclared function 'setresuid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here
Any suggestions to solve this? Many thanks
Thanks to @Kalis suggestion. What I missed is the cross compiler.
Source: https://github.com/SergioBenitez/homebrew-osxct Another source: https://github.com/messense/homebrew-macos-cross-toolchains (haven't tested yet).