I am working on a GO project that links to a shared library (.so
) using CGO
. I want to embed the library path in the binary using rpath
,so that it runs without needing to set the LD_LIBRARY_PATH
. However, my Go test binary only works when I manually set the LD_LIBRARY_PATH
but fails when relying on rpath
alone.
This works:
unit-test:
@(export LD_LIBRARY_PATH=${LIB_PATH}:${LD_LIBRARY_PATH}; \
CGO_LDFLAGS="-Wl,-rpath,${LIB_PATH} -L${LIB_PATH} -l<some_lib>" ${GOEXE} test -coverprofile=coverage.out ./...)
but the following doesn't
@CGO_LDFLAGS="-Wl,-rpath,${LIB_PATH} -L${LIB_PATH} -l<some_lib>"
${GOEXE} test -coverprofile=coverage.out ./...
I have tried this on both Ubuntu 22.04 and OpenSuse 15. Am I missing any configuration?
Thanks!