0

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.

Dinesh Reddy
  • 775
  • 1
  • 11
  • 25
  • This question is specific to "CGO" and I feel this is not related to the https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Dinesh Reddy Apr 27 '19 at 12:38
  • Finally go community helped to identify the problem. There was extern "C" missing in my header. after re building the library, linking issue is solved. More details [here](https://github.com/golang/go/issues/31723) – Dinesh Reddy Apr 29 '19 at 06:49

0 Answers0