Hi all,
I’m trying to statically compile a go program with the SAP NetWeaver libraries.
If I just build like this:
$ go build hello_gorfc.go
It creates an executable that works (it connects to an SAP system, and obtains relevant data), but it is dynamically linked:
$ file hello_gorfc
hello_gorfc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2, BuildID[sha1]=0e44420f833955509aa381f3d18dd3d447d398ca, for
GNU/Linux 3.2.0, not stripped
$ ldd hello_gorfc
linux-vdso.so.1 (0x00007ffdf0191000)
libsapnwrfc.so => /usr/local/sap/nwrfcsdk/lib/libsapnwrfc.so (0x00007f5b5d765000)
libsapucum.so => /usr/local/sap/nwrfcsdk/lib/libsapucum.so (0x00007f5b5d42b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5b5d408000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5b5d216000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5b5d210000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5b5d205000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f5b5d1fa000)
If I try to compile it statically, it fails. I’ve try all kinds of parameter combinations:
$ go build -ldflags '-linkmode external -extldflags "-static"' -a hello_gorfc.go
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lsapnwrfc
/usr/bin/ld: cannot find -lsapucum
collect2: error: ld returned 1 exit status
$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags '-linkmode external -extldflags "-static"' -a hello_gorfc.go
package command-line-arguments: build constraints exclude all Go files in /home/appuser
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-linkmode external -extldflags "-static"' -a hello_gorfc.go
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lsapnwrfc
/usr/bin/ld: cannot find -lsapucum
collect2: error: ld returned 1 exit status
I appreciate any help you can give me. Let me know if you need more details to make an assessment.
Thanks in advance
papibe