Linking .so Shared Object File with Relative Path in GCC (G++)
June 25, 2022•59 words
These options must be together for finding the .so files:
-Wl,-rpath,RELATIVE_PATH_FROM_DOT
-LRELATIVE_PATH_FROM_DOT
-l:DSO_FILE_NAME
For example:
g++ -shared -o file.so file.cpp -fPIC -Wl,-rpath,. -L. -l:mylib.so
g++ -shared -o file.so file.cpp -fPIC -wl,-rpath,./libs -L./libs -l:mylib.so
The -Wl,-rpath
and -L
must be together, and the -l
must come with colon
after to specify the exact file name.