Lets say I have this:
../project_dir
main.cpp
mylib.cpp
mylib.h
Building steps will be:
g++ -c mylib.cpp -o mylib.o
g++ -shared -o libmylib.so mylib.o
g++ -L$(pwd) -Wl,-rpath='$ORIGIN' -o exec main.cpp -lmylib
exec
will be my binary executable output. When I testing with:
ldd exec
the output line is:
libmylib.so => /full/path/to/build/directory/libmylib.so (0x00007f75fdd1f000)
That output line is my question, is it possible to get:
libmylib.so => ./libmylib.so
so whenever I move the executable file, I can move the shared library along with it. If it is possible, how to do this with cmake?
Juste add in your CMakefiles.txt
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) # only if you want copy from the build tree
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With