为什么 cmake 的安装文件与实际构建的二进制文件不同?
Why does cmake's installed files differ from the actual built binary?
我正在使用 CMake 在 ubuntu 中构建几个库,我注意到每当我尝试使用已安装目录中的文件时,都会出现缺少库的错误。使用 ldd
我注意到在这些文件中找不到库,而如果我返回构建的原始文件,它包含所有引用并将其复制到安装目录可以解决问题。
为了使所有这些更清楚,请考虑以下我用来构建库的 CMakeList.txt:
cmake_minimum_required(VERSION 3.11)
project(AntiSpoofer)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INSTALL_PREFIX /home/me/Desktop/LibtorchPort/built_stuff)
add_definitions(-D_ANTISPOOFER_BUILD_DLL)
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
include_directories( /home/me/Desktop/LibtorchPort/Dependencies/include ${TORCH_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
set(ANTISPOOFER_SRC ./AntiSpoofer.cpp )
add_library(
AntiSpoofer_dynamic
SHARED
${ANTISPOOFER_SRC}
)
target_link_directories(AntiSpoofer_dynamic PUBLIC /home/me/Desktop/LibtorchPort/Blinker/build)
set(LIBS ${LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS} Blinker)
# Link
target_link_libraries(AntiSpoofer_dynamic ${LIBS})
install(TARGETS AntiSpoofer_dynamic DESTINATION lib)
这是我调用 cmake 的方式:
cmake -DCMAKE_PREFIX_PATH="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" ..
然后进行 make install。
现在,当我导航到 AntiSpoofer/build
并在创建的对象上获取 MD5 散列时,这就是我得到的:
ldd libAntiSpoofer_dynamic.so
的输出如下:
linux-vdso.so.1 (0x00007ffc23bf6000)
libtorch.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so (0x00007f5cd35f2000)
libBlinker.so => /home/hossein/Desktop/LibtorchPort/Blinker/build/libBlinker.so (0x00007f5cd355e000)
libtorch_cpu.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so (0x00007f5cc36af000)
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007f5cc26d4000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5cc24dc000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5cc24bf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5cc22cd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5cc22aa000)
libc10.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libc10.so (0x00007f5cc2026000)
libopencv_highgui.so.3.4 => /usr/local/lib/libopencv_highgui.so.3.4 (0x00007f5cc200d000)
libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007f5cc048c000)
libcblas.so.3 => /lib/x86_64-linux-gnu/libcblas.so.3 (0x00007f5cc0465000)
liblapack.so.3 => /lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f5cbfd9d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5cbfc4e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5cd3844000)
libgomp-7c85b1e2.so.1 => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libgomp-7c85b1e2.so.1 (0x00007f5cbfa24000)
libtensorpipe.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtensorpipe.so (0x00007f5cbf55b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5cbf550000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5cbf548000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5cbf52c000)
libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f5cbed7b000)
libgdk-3.so.0 => /lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007f5cbec76000)
libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f5cbeb53000)
libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f5cbeb29000)
libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f5cbeac9000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f5cbe9a0000)
libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007f5cbe85b000)
libatlas.so.3 => /lib/x86_64-linux-gnu/libatlas.so.3 (0x00007f5cbe4cf000)
libblas.so.3 => /lib/x86_64-linux-gnu/libblas.so.3 (0x00007f5cbe107000)
libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f5cbde43000)
libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f5cbde3d000)
libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f5cbde2b000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f5cbdcee000)
libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f5cbdcdc000)
libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f5cbdcd2000)
libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f5cbdcc6000)
libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f5cbdc9c000)
libatk-bridge-2.0.so.0 => /lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 (0x00007f5cbdc65000)
libepoxy.so.0 => /lib/x86_64-linux-gnu/libepoxy.so.0 (0x00007f5cbdb32000)
libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x00007f5cbdb15000)
libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f5cbd932000)
libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f5cbd919000)
libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f5cbd8ca000)
libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f5cbd7c5000)
libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f5cbd77e000)
libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f5cbd6bf000)
libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f5cbd6b8000)
libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f5cbd6ab000)
libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f5cbd69e000)
libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f5cbd699000)
libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f5cbd694000)
libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f5cbd650000)
libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f5cbd645000)
libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f5cbd640000)
libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f5cbd62f000)
libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f5cbd61a000)
libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f5cbd573000)
libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f5cbd539000)
libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f5cbd534000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f5cbd50a000)
libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f5cbd4fb000)
libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f5cbd2f1000)
libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007f5cbd2e5000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f5cbd270000)
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f5cbd1eb000)
libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f5cbd16a000)
libIlmImf-2_3.so.24 => /lib/x86_64-linux-gnu/libIlmImf-2_3.so.24 (0x00007f5cbce8c000)
libquadmath.so.0 => /lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f5cbce42000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f5cbcdef000)
libatspi.so.0 => /lib/x86_64-linux-gnu/libatspi.so.0 (0x00007f5cbcdb8000)
libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007f5cbcd58000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f5cbcd2d000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f5cbcd11000)
libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x00007f5cbcd04000)
libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f5cbccd7000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f5cbcca9000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f5cbcca0000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f5cbcc9a000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f5cbcc90000)
libwebp.so.6 => /lib/x86_64-linux-gnu/libwebp.so.6 (0x00007f5cbca27000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f5cbc97e000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f5cbc955000)
libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f5cbc747000)
libHalf.so.24 => /lib/x86_64-linux-gnu/libHalf.so.24 (0x00007f5cbc700000)
libIex-2_3.so.24 => /lib/x86_64-linux-gnu/libIex-2_3.so.24 (0x00007f5cbc6df000)
libIlmThread-2_3.so.24 => /lib/x86_64-linux-gnu/libIlmThread-2_3.so.24 (0x00007f5cbc6d5000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f5cbc628000)
libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f5cbc5d1000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f5cbc53f000)
libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f5cbc535000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f5cbc51b000)
liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f5cbc4fa000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f5cbc3dc000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f5cbc3b7000)
很好,没问题。但是,安装目录中的 lib 文件具有完全不同的 MD5 哈希和 ldd 输出:
ldd 输出:
linux-vdso.so.1 (0x00007ffcec9c5000)
libtorch.so => not found
libBlinker.so => not found
libtorch_cpu.so => not found
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007fe00f5f5000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe00f414000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe00f3f9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe00f205000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe00f1ff000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe00f1dc000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe00f1c0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe00f071000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe010624000)
这里有什么问题?这是一个 CMake 错误吗?还是与 OS (Ubuntu 20.04) 或两者都不相关?
这是 CMake 中的正常行为。
编译二进制文件时,依赖项的 rpath 在二进制文件中设置,但在安装时被删除。
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. When installing, it will clear the RPATH of
these targets so they are installed with an empty RPATH.
Source
查找运行时依赖项时,rpath 优先于默认目录(参见 )。
但是由于 rpath 已从您的库中删除,因此它不知道您 "out-of-default-directories"-dependencies.
您可以使用 LD_LIBRARY_PATH
、LD_PRELOAD
或使用 ldconfig
.
将附加路径添加到查找目录来操作查找
我正在使用 CMake 在 ubuntu 中构建几个库,我注意到每当我尝试使用已安装目录中的文件时,都会出现缺少库的错误。使用 ldd
我注意到在这些文件中找不到库,而如果我返回构建的原始文件,它包含所有引用并将其复制到安装目录可以解决问题。
为了使所有这些更清楚,请考虑以下我用来构建库的 CMakeList.txt:
cmake_minimum_required(VERSION 3.11)
project(AntiSpoofer)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INSTALL_PREFIX /home/me/Desktop/LibtorchPort/built_stuff)
add_definitions(-D_ANTISPOOFER_BUILD_DLL)
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
include_directories( /home/me/Desktop/LibtorchPort/Dependencies/include ${TORCH_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
set(ANTISPOOFER_SRC ./AntiSpoofer.cpp )
add_library(
AntiSpoofer_dynamic
SHARED
${ANTISPOOFER_SRC}
)
target_link_directories(AntiSpoofer_dynamic PUBLIC /home/me/Desktop/LibtorchPort/Blinker/build)
set(LIBS ${LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS} Blinker)
# Link
target_link_libraries(AntiSpoofer_dynamic ${LIBS})
install(TARGETS AntiSpoofer_dynamic DESTINATION lib)
这是我调用 cmake 的方式:
cmake -DCMAKE_PREFIX_PATH="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" ..
然后进行 make install。
现在,当我导航到 AntiSpoofer/build
并在创建的对象上获取 MD5 散列时,这就是我得到的:
ldd libAntiSpoofer_dynamic.so
的输出如下:
linux-vdso.so.1 (0x00007ffc23bf6000)
libtorch.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so (0x00007f5cd35f2000)
libBlinker.so => /home/hossein/Desktop/LibtorchPort/Blinker/build/libBlinker.so (0x00007f5cd355e000)
libtorch_cpu.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so (0x00007f5cc36af000)
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007f5cc26d4000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5cc24dc000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5cc24bf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5cc22cd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5cc22aa000)
libc10.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libc10.so (0x00007f5cc2026000)
libopencv_highgui.so.3.4 => /usr/local/lib/libopencv_highgui.so.3.4 (0x00007f5cc200d000)
libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007f5cc048c000)
libcblas.so.3 => /lib/x86_64-linux-gnu/libcblas.so.3 (0x00007f5cc0465000)
liblapack.so.3 => /lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f5cbfd9d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5cbfc4e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5cd3844000)
libgomp-7c85b1e2.so.1 => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libgomp-7c85b1e2.so.1 (0x00007f5cbfa24000)
libtensorpipe.so => /home/hossein/anaconda3/lib/python3.8/site-packages/torch/lib/libtensorpipe.so (0x00007f5cbf55b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5cbf550000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5cbf548000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5cbf52c000)
libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f5cbed7b000)
libgdk-3.so.0 => /lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007f5cbec76000)
libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f5cbeb53000)
libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f5cbeb29000)
libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f5cbeac9000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f5cbe9a0000)
libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007f5cbe85b000)
libatlas.so.3 => /lib/x86_64-linux-gnu/libatlas.so.3 (0x00007f5cbe4cf000)
libblas.so.3 => /lib/x86_64-linux-gnu/libblas.so.3 (0x00007f5cbe107000)
libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f5cbde43000)
libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f5cbde3d000)
libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f5cbde2b000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f5cbdcee000)
libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f5cbdcdc000)
libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f5cbdcd2000)
libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f5cbdcc6000)
libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f5cbdc9c000)
libatk-bridge-2.0.so.0 => /lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 (0x00007f5cbdc65000)
libepoxy.so.0 => /lib/x86_64-linux-gnu/libepoxy.so.0 (0x00007f5cbdb32000)
libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x00007f5cbdb15000)
libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f5cbd932000)
libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f5cbd919000)
libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f5cbd8ca000)
libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f5cbd7c5000)
libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f5cbd77e000)
libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f5cbd6bf000)
libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f5cbd6b8000)
libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f5cbd6ab000)
libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f5cbd69e000)
libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f5cbd699000)
libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f5cbd694000)
libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f5cbd650000)
libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f5cbd645000)
libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f5cbd640000)
libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f5cbd62f000)
libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f5cbd61a000)
libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f5cbd573000)
libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f5cbd539000)
libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f5cbd534000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f5cbd50a000)
libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f5cbd4fb000)
libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f5cbd2f1000)
libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007f5cbd2e5000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f5cbd270000)
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f5cbd1eb000)
libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f5cbd16a000)
libIlmImf-2_3.so.24 => /lib/x86_64-linux-gnu/libIlmImf-2_3.so.24 (0x00007f5cbce8c000)
libquadmath.so.0 => /lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f5cbce42000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f5cbcdef000)
libatspi.so.0 => /lib/x86_64-linux-gnu/libatspi.so.0 (0x00007f5cbcdb8000)
libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007f5cbcd58000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f5cbcd2d000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f5cbcd11000)
libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x00007f5cbcd04000)
libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f5cbccd7000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f5cbcca9000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f5cbcca0000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f5cbcc9a000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f5cbcc90000)
libwebp.so.6 => /lib/x86_64-linux-gnu/libwebp.so.6 (0x00007f5cbca27000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f5cbc97e000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f5cbc955000)
libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f5cbc747000)
libHalf.so.24 => /lib/x86_64-linux-gnu/libHalf.so.24 (0x00007f5cbc700000)
libIex-2_3.so.24 => /lib/x86_64-linux-gnu/libIex-2_3.so.24 (0x00007f5cbc6df000)
libIlmThread-2_3.so.24 => /lib/x86_64-linux-gnu/libIlmThread-2_3.so.24 (0x00007f5cbc6d5000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f5cbc628000)
libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f5cbc5d1000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f5cbc53f000)
libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f5cbc535000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f5cbc51b000)
liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f5cbc4fa000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f5cbc3dc000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f5cbc3b7000)
很好,没问题。但是,安装目录中的 lib 文件具有完全不同的 MD5 哈希和 ldd 输出:
ldd 输出:
linux-vdso.so.1 (0x00007ffcec9c5000)
libtorch.so => not found
libBlinker.so => not found
libtorch_cpu.so => not found
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007fe00f5f5000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe00f414000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe00f3f9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe00f205000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe00f1ff000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe00f1dc000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe00f1c0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe00f071000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe010624000)
这里有什么问题?这是一个 CMake 错误吗?还是与 OS (Ubuntu 20.04) 或两者都不相关?
这是 CMake 中的正常行为。 编译二进制文件时,依赖项的 rpath 在二进制文件中设置,但在安装时被删除。
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. When installing, it will clear the RPATH of these targets so they are installed with an empty RPATH. Source
查找运行时依赖项时,rpath 优先于默认目录(参见
您可以使用 LD_LIBRARY_PATH
、LD_PRELOAD
或使用 ldconfig
.