Qmake and passing $ORIGIN to linker option -rpath
If you want $ORIGIN
to be (properly) evaluated while building you can simply add this to your .pro
file:
QMAKE_RPATHDIR += $ORIGIN/../mylibs
RPATH in .pro-file not working
It is here "qmake and rpath":
You have to use the $ORIGIN feature of the runtime linker.
Unfortunately, due to some brilliant foresight of the loader devs,
they used '$' as prefix, which makes it a royal pain in the ass to
pass around. It's impossible to use it in QMAKE_RPATHDIR. You must
instead use:QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN\''
so that it survives both the project file as well as the Makefile.
In your command line it goes to shell as -Wl,-rpath,$ORIGIN
and $ORIGIN
is expanded, since the $ dollar sign is interpreted by the shell. It should be quoted. Example of such quotation is also provided in LD.SO(8) man page: gcc -Wl,-rpath,'$ORIGIN/../lib'
.
How do I enforce the order of qmake library dependencies?
The .pc file(s) for mylib1, mylib2 may be incomplete.
If those libraries depend on -lboost_date_time
and -lboost_signals
, then the .pc files should already pull in those dependencies by:
Libs: -lboost_date_time -lboost_signals
...and qmake will put them at the correct place in the link line. No need to explicitly put them in the .pro file :)
Setting rpath for dependencies of dependencies?
I ended up not doing anything at build time, and instead added a post-build step to my CMake where I run patchelf to change all the rpaths to $ORIGIN:
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_custom_command(
TARGET Client POST_BUILD
COMMAND find ${OUTPUT_DIR} -type f -maxdepth 1 -exec patchelf --set-rpath '\$\$ORIGIN' {} \\\;
)
endif()
To be more complete for anyone reading around, the more-normal path is to have an install step where you put your files in the appropriate directories and make use of already-installed system shared libs. In my case an install step wouldn't be appropriate, so I'm adding custom commands after the build step to copy my dependencies into a directory with the executable and modify the rpath so they get loaded properly.
understanding external library path qmake
- The statement
-L"PATH"
means addPATH
the library search
directory list. - The statement
-lOMD
means load libraryOMD
during linking.
It seems somehow your library is already in the library search path.
Which means LIBS += -lOMD
will also work. Aside from some runtime libraries you have to specify the libraries to load.
edit:/usr/lib
is a default library search path. If you manually copy the library there, it will be found.
Change position of a variable in Makefile which is added to the Makefile via qmake
I found a way to handle the problem: If we use a global variable as the path to the library, it's not a good idea to set the rpath
as follows:
QMAKE_LFLAGS += -Wl,--rpath=\\\$\CUSTOMPATH
Instead, we could use QMAKE_RPATHDIR
:
QMAKE_RPATHDIR += $${CUSTOMPATH}
Related Topics
Elf Program Header Virtual Address and File Offset
Using Perf to Monitor Raw Event Counters
How to Pass All Arguments with Xargs in Middle of Command in Linux
Determine the Os Version, Linux and Windows from Powershell
Get the Characters After the Last Index of a Substring from a String
When Should Xargs Be Preferred Over While-Read Loops
Determine If Relative or Absolute Path in Shell Program
Ubuntu Equivalent of Yum's Whatprovides, to Find Which Package Provides a File
Hook into Linux Key Event Handling
Lowest Latency Notification Method Between Process Under Linux
Coreos - Get Docker Container Name by Pid
Which Stack Is Used by Interrupt Handler - Linux
Rename Multiple Directories Matching Pattern
How to Repeat a Dash (Hyphen) in Shell
How to Speed Up Compilation Time in Linux
Using --Http2.0 Option with Curl 7.33.0 Gives Unsupported Protocol