CMake: Linking shared lib with other libs with relative path for distribution
I've made some more tests and actually, the use of SET (CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,$ORIGIN/libs")
solved the problem.
relative paths for shared libraries
How I can make the linking of the libraries relative to the parent program folder
Depends on your operating system. On Linux, this will probably work:
g++ -shared -o wrapper.so -Wl,-rpath='$ORIGIN' src/wrapper.o one.so two.so
Note: single quotes are important in above command.
Can you relink/modify relative shared library look up paths?
Is there a way I can poke the files Ai.so and tell them "Hey that other library whose symbols you need is actually over here now"?
You can use patchelf to do that, but you shouldn't.
Since you control how A*.so
is built, you should set their RPATH
so that it works "out of the box". Adding -rpath=/path/to/BLibraries
to A*.so
link command is probably all that's needed.
How to link a shared library with CMake with relative path
From the documentation:
By default if you don't change any RPATH related settings, CMake will link the executables and shared libraries with full RPATH to all used libraries in the build tree.
This is the behaviour you are seeing.
However, there are a number of ways to change this to match the behaviour you require.
Some examples from the above linked docs:
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "")
# don't add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
Using the above you'll likely want to set CMAKE_INSTALL_RPATH
and then distribute the installed binary.
If you want to distribute from the binary in your build tree, it is also possible to bypass CMake's rpath handling and modify the rpath directly using linker flags:
set_target_properties(game PROPERTIES LINK_FLAGS "-Wl,-rpath,./")
Related Topics
Automatic Login on Angstrom Linux
Embedding the Password in the Bash Script
Trying to Ping Linux Vm Hosted on Azure Does Not Work
How to Force Cp to Overwrite Without Confirmation
How to Get Sudo Access for a File Inside the Vi Text Editor
How to Make Grep Print the Lines Below and Above Each Matching Line
How to Grep a String in a Directory and All Its Subdirectories
Signals and Interrupts a Comparison
Starting a Shell in the Docker Alpine Container
How to Append Contents of Multiple Files into One File
How to Export Database Schema in Oracle to a Dump File
How to Divide in the Linux Console
Genymotion Throws Libssl_Conf.So: Cannot Open Shared Object File: No Such File or Directory
Can't Remove a Directory in Unix
How to Change(Hide) the Nginx Server Signature
What Is the Pid in the Host, of a Process Running Inside a Docker Container
Best Posix Way to Determine If a Filesystem Is Mounted Read Only