I would like to use a dynamic C library from a go application, I can build the application but the library is not found at runtime. Here the structure of my project:
src/ctest/
|- lib/
| |- libmylib.so
| |- libmylib.h
|- main.go
in main.go I import the .h and .so files:
/*
#cgo CFLAGS: -I./lib
#cgo LDFLAGS: -L./lib -lmylib
#include <mylib.h>
*/
import "C"
func main() {
C.testMyLib()
}
I can build the application successfully, but when launched it throws this error:
error while loading shared libraries: libmylib.so.0: cannot open shared object file: No such file or directory
If I copy the libmylib.so file in /usr/lib then everything works as expected; however, I would like that my application automatically searches for the needed library in CURRENT_PATH/lib at runtime without setting environment variables. How can I achieve it?