I am using CMake to build a cross platform project. For the moment I am trying to run it on Linux. I have recently added a project for running tests, but it will not run because it cannot find one of the shared libraries, specifically libtbbmalloc.so.2
:
/tests: error while loading shared libraries: libtbbmalloc.so.2: cannot open shared object file: No such file or directory`
When I run ldd
on the executable I get the following:
linux-vdso.so.1 (0x00007fffeb572000)
libtbbmalloc_proxy.so.2 => /home/username/dev/tbb/libtbbmalloc_proxy.so.2 (0x00007f50afe00000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f50afa70000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f50af6d0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f50af4b0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f50af0a0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f50aee90000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f50aec70000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f50aea60000)
/lib64/ld-linux-x86-64.so.2 (0x00007f50b0400000)
libtbbmalloc.so.2 => not found
The CMakeLists.txt for my test project looks like this:
set(test_sourcefiles main_tests.cpp)
add_executable(tests ${test_sourcefiles})
target_link_libraries(tests Catch2::Catch2 MyLib)
MyLib uses tbb, and I guess that is why my executable (tests) searches for it. When running ldd on MyLib it finds the library (libtbbmalloc.so.2):
(removed some output for readability)
libtbbmalloc_proxy.so.2 => /home/username/dev/tbb/libtbbmalloc_proxy.so.2 (0x00007f9af8110000)
libtbbmalloc.so.2 => /home/username/dev/tbb/libtbbmalloc.so.2 (0x00007f9ac4eb0000)
I have tried specifically adding libttbbmalloc.so.2 in my tests/CMakeLists.txt target_link_libraries(${project} /home/username/dev/tbb/libtbbmalloc.so.2)
, but it makes no difference.
If I add /home/username/dev/tbb/
to LD_LIBRARY_PATH
, the program runs, and ldd reports that libtbbmalloc.so.2 is found.
Any ideas on what I might be doing wrong, and how can I get my program to run without setting LD_LIBRARY_PATH
?
Update: I found out that it's possible to print runpath/rpath by using chrpath -l name-of-executable
. When using this tool on my executable, it looks like the folder with libtbbmalloc.so.2 is added to runpath, but the program still won't run:
larjr@DESKTOP:~/dev/project/build/tests$ chrpath -l tests
tests: RUNPATH=/home/larsjr/dev/project/build/MyLib:/home/username/dev/tbb
ldd
commands show that your library is correctly resolved (found). So if you run your tests at the same build location, it shoud work. The answer by @Zaffy assumes that your problem is after the installation of your program. Is that the problem? – Notarizeldd
command (should perhaps have highlighted this) shows that it cannot resolvelibtbbmalloc.so.2
. when building the test project, right? What I do not understand is why one project MyLib, works correctly, while my tests project does not. – Powerldd
output says thatlibtbbmalloc_proxy.so.2
is correctly resolved, butlibtbbmalloc.so.2
is not! And that explains it. Your program links to the proxy library, so the RPATH of your program is used to locate this one. But the real library is not linked to your program, it is linked to the proxy library. And the proxy library does not have an embedded RPATH to help the linker to locate the buddy. – Notarizetests
project, but it still cannot be found. – Powerpatchelf
the proxy library to insert aRPATH
on it, or 2: simply install the libraries on your system at some standard prefix like /usr/local/ that is included in your/etc/ld.so.conf
– Notarize