I have a C++ shared library in /opt/xx/lib64
. Headers are in C.
In my go code, I am including proper header and linker options using CPPFLAGS/CFLAGS and LDFLAGS. Still while building go I am getting 'undefined reference` error.
import (
//#cgo LDFLAGS: -L/opt/xxx/lib64/ -lsessionmgmt
//#cgo CPPFLAGS: -I/opt/xxx/include/
//#include <stdlib.h>
//#include <sessionMgmt/sessionMgmt.h>
"C"
"unsafe"
)
/tmp/go-build609413262/b163/_x002.o: In function `_cgo_e38947506e9d_Cfunc_um_get_lastlogin_info':
/tmp/go-build/cgo-gcc-prolog:52: undefined reference to `um_get_lastlogin_info'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:48: vet] Error 2
Library is exist in the right path and do contain the required method. Not sure why this error.
$ grep um_get_lastlogin_info /opt/xxx/lib64/libsessionmgmt.so
Binary file /opt/xxx/lib64/libsessionmgmt.so matches
Also tried using the pkg-config
with cgo. Still the same linking error appears.