找不到cmake交叉编译的手臂过渡依赖库

时间:2019-10-02 14:19:10

标签: cmake

我有一个C ++大型程序,可以为Jetson TX2交叉编译 该程序的结构如下:

root  
| - module1  
| | - CMakeLists.txt  
| - module2  
| | - CMakeLists.txt  
| - CMakeLists.txt  
| - toolchain.cmake

每个模块子文件夹都创建一个共享库,供我的主要目标链接。
Jetson的工具链是

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CROSS_COMPILE "jetson")

SET(CMAKE_C_COMPILER   aarch64-linux-gnu-gcc-5)
SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-gcc-5)

SET(CMAKE_SYSROOT /usr/local/sysroot_jetson)

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig:${CMAKE_SYSROOT}/usr/local/lib/pkgconfig:${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

到目前为止,我还没有任何问题,直到现在我需要包括一个具有tensorflow依赖关系的新模块。

我已经在/ usr / local / lib中安装了tensorflow_cc库。 该TF库是在GPU支持下进行编译的,因此可以链接Jetson上安装的cuda-9.0的许多功能。

模块的CMakeLists.txt只需链接到tensorflow,如下所示。
当然,这是简化的。

target_link_libraries(${LIB_NAME} -ltensorflow_cc)

只要我不交叉编译就可以了。
直接在jetson或我的主机上编译可以正常工作。

但是添加工具链无济于事。
编译时,tensorflow模块的共享库实际上可以很好地编译,但是链接最终目标只是输出以下内容

/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcublas.so.9.0, needed by /usr/local/sysroot_jetson/usr/local/lib/libtensorflow_cc.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcusolver.so.9.0, needed by /usr/local/sysroot_jetson/usr/local/lib/libtensorflow_cc.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcudart.so.9.0, needed by /usr/local/sysroot_jetson/usr/local/lib/libtensorflow_cc.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcuda.so.1, needed by /usr/local/sysroot_jetson/usr/local/lib//libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcufft.so.9.0, needed by /usr/local/sysroot_jetson/usr/local/lib//libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libcurand.so.9.0, needed by /usr/local/sysroot_jetson/usr/local/lib//libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
/usr/local/sysroot_jetson/usr/local/lib//libtensorflow_framework.so: undefined reference to `cublasDrotm_v2@libcublas.so.9.0'
/usr/local/sysroot_jetson/usr/local/lib/libtensorflow_cc.so: undefined reference to `cusolverDnZgeqrf@libcusolver.so.9.0'
/usr/local/sysroot_jetson/usr/local/lib//libtensorflow_framework.so: undefined reference to `cuEventElapsedTime'
......

所有必需的文件都可以在sysroot中的/ usr / local / sysroot_jetson / usr / local / cuda / lib64中找到

我的理解是/etc/ld.so.conf.d中设置的所有ld额外路径都不会使用或读取。
我应该能够指示cmake查找那些额外的搜索路径,但我尝试了所有可以阅读的内容,而没有进行任何更改。 pkg-config具有所有cuda库的文件,因此我可以

pkg_check_modules(cudaall REQUIRED cuda-9.0 cublas-9.0 cusolver-9.0 cudart-9.0 cufft-9.0 curand-9.0)

它找到了他们,但是失败了

/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcublas
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcusolver
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcudart
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcufft
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcurand

添加-L $ {CMAKE_SYSROOT} /usr/local/cuda-9.0/lib64(我不应该这样做)只是导致找不到其他nvidia库。

/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libnvrm_gpu.so, needed by /usr/local/sysroot_jetson/usr/lib/aarch64-linux-gnu/libcuda.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libnvrm.so, needed by /usr/local/sysroot_jetson/usr/lib/aarch64-linux-gnu/libcuda.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libnvidia-fatbinaryloader.so.28.2.1, needed by /usr/local/sysroot_jetson/usr/lib/aarch64-linux-gnu/libcuda.so, not found (try using -rpath or -rpath-link)

我真正不明白的是,为什么要关心tensorflow_cc.so链接的哪些库?
那不是运行时问题吗?
我不能只在编译时关心tensorflow_cc.so的依赖项吗?

这一切都让我感到困惑。

任何见识都会得到深深的赞赏。

0 个答案:

没有答案