meson: rpath doesn't get set with find_library('foo', dirs:'/path/to/lib')
Hi Jussi,
If you build a shared object with meson, the rpath get sets correctly (or so the docs say), but when I use find_library() and give it a search path, the rpath doesn’t get set. This is causing me lot of pain.
I’m currently doing stuff like this:
thirdparty_root = '/usr/local/thirdparty-1.6.0'
thirdparty_lib = [thirdparty_root + '/lib/linux-x64-all',
thirdparty_root + '/lib/linux-x64-gcc4.8'
]
thirdparty_rpath = thirdparty_lib[0] + ':' + thirdparty_lib[1]
thirdparty_dep = declare_dependency(
include_directories: thirdparty_inc,
dependencies: [
find_library('lib1', dirs: thirdparty_lib),
find_library('lib2', dirs: thirdparty_lib),
find_library('lib3', dirs: thirdparty_lib)
]
)
Then doing this:
executable('foo', 'foo.cpp',
...,
link_args: '-Wl,-rpath,@0@:@1@'.format(thirdparty_rpath, boost_rpath),
)
Am I doing it wrong?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 56 (36 by maintainers)
Commits related to this issue
- fwupd: bump — committed to vcunat/nixpkgs by shlevy 7 years ago
- py-meson: add workaround for rpath stripping. By default, meson strips all rpaths, see https://github.com/mesonbuild/meson/issues/314 Remove the stripping (which might leave build rpaths inside inst... — committed to NetBSD/pkgsrc by deleted user 6 years ago
- meson: prevent RPATH stripping By default, Meson strips RPATH from the executable it builds [1,2]. This will make support/scripts/check-host-rpath fail. So add a patch to prevent RPATH from being st... — committed to elebihan/buildroot by elebihan 6 years ago
- meson: prevent RPATH stripping By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when ... — committed to buildroot/buildroot by elebihan 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to mesonbuild/meson by nirbheek 6 years ago
- meson: prevent RPATH stripping By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when ... — committed to ananos/buildroot by elebihan 6 years ago
- pkgconfig deps: Also resolve paths to shared libraries This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries ... — committed to noverby/meson by nirbheek 6 years ago
- meson: prevent RPATH stripping By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when ... — committed to AndreRH/buildroot by elebihan 6 years ago
I don’t think this is fixed.
Here is a reproduction scenario:
@NickeZ This is a bug. It’s specific to platforms that use ELF (which doesn’t include Darwin). Solving it has no security repercussions whatsoever: if you believe that it does, you should also wipe rpath in Mach-O binaries, so it’s a bug either way.
https://github.com/mesonbuild/meson/blob/db34a3a7017d0096faa8d3f020efd078ad8a65e1/mesonbuild/scripts/depfixer.py#L287-L318
The problem here is that this overwrites existing rpath instead of appending
install_rpath
to it. (Moreover, it seems that if I setinstall_rpath
to be long enough, this will fail).This should not be a post-build fixup as it currently is: flags should be passed to the compiler to append to existing rpath. Also it doesn’t make sense that
install_rpath
doesn’t do anything on Darwin as Mach-O has@rpath
. Sorry, but overwriting ELF headers is a dirty hack.No other build system has this problem, because no other build system touches ELF headers. If build system ignores compile/linker flags, it doesn’t do its job properly. Remember SCons? 😃
FWIW, on nixpkgs we just patch meson now and everything works as desired https://github.com/NixOS/nixpkgs/commit/8f95aef531de13e6fffc62a31b4106f745d647ec
We changed our behaviour to do the same just this last release. The commit to do that is this one.
That is only applied inside the build dir, it is stripped on install like the other ones.
Based solely on description
CMAKE_INSTALL_RPATH_USE_LINK_PATH
seems to be the behavior that @rhd is interested in when they opened this ticket. I would also like to see an equivalent toCMAKE_INSTALL_RPATH
which gives the builder full control over the final rpath.I’m not sure how you can use rpath in meson. But I would say that the use case should be strictly limited to libraries that are compiled within the same project. Meson shouldn’t support public dependencies in non-standard locations because this is not related to building a project. Definitely not through the build file syntax.
I think package managers that needs this funcitonality should run some post-build command to add rpaths.
Anyways this isn’t supported on windows binaries so it would give meson a platform dependent feeling.