After reading articles I tried this:
env GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o hello.so testlib.go
It gave an error:
go: no Go source files
Then I enabled CGO by doing this:
env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -buildmode=c-shared -o hello.so testlib.go
and it gave a set of errors:
env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -buildmode=c-shared -o hello.so testlib.go
# runtime/cgo
linux_syscall.c:67:13: error: implicit declaration of function 'setresgid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: implicit declaration of function 'setresuid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here
Below are the versions:
Go: go version go1.19.4 darwin/amd64
GCC:
=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin