我正在为我的一个基于 cmake 的 C++ 项目解决交叉编译问题。
我的项目使用了许多外部库。我已经设法在目标环境中构建并安装了其中的一些(即 sshfs-mounte:每次构建库时,我都会立即将其安装在目标上),例如 Boost、Glog、Protobuf、Gtest 等.
在构建我自己的项目时出现了问题,它似乎与变量的使用有关CMAKE_FIND_ROOT_PATH
。
事实上,我构建和安装的一些依赖项$TARGET_FS/usr/lib
在$TARGET_FS/usr/local/lib
. 我似乎无法通过使用上述变量让 cmake 找到所有这些。
我目前正在使用交叉编译的 cmake 文件,toolchain-arm.cmake
其内容如下:
SET(TARGET_CC arm-linux-gnueabi-gcc-4.6)
SET(TARGET_CXX arm-linux-gnueabi-g++-4.6)
SET(CMAKE_CXX_FLAGS "-fpic -ffunction-sections -funwind-tables -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -Wa,--noexecstack")
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER ${TARGET_CC})
SET(CMAKE_CXX_COMPILER ${TARGET_CXX})
SET(CMAKE_FIND_ROOT_PATH "${TARGET_FS}/usr/local")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
我通过发出以下命令来调用 cmake 过程
cmake -DTARGET_FS=<path/to/target/fs> -DCMAKE_BUILD_TYPE=optimized -DCMAKE_TOOLCHAIN_FILE=../../Cross/toolchain-arm.cmake ../../
CMake 抱怨缺少一些依赖项:那些存在的依赖项${TARGET_FS}/usr/lib
(请注意,我对编译器的提示find_root_path
是 about ${TARGET_FS}/usr/local/lib
,所以我有点期待这种行为)。我需要一种方法来指定多个路径CMAKE_FIND_ROOT_PATH
,但简单地用空格分隔它们并将它们括在双引号之间似乎不是要走的路(SET(CMAKE_FIND_ROOT_PATH "${TARGET_FS}/usr/local ${TARGET_FS}/usr")
)。
有没有人对如何面对这个问题有任何提示?
编辑回答谢尔盖的评论
当前设置给出了这个输出
Boost Libraries Found:
$TARGET_FS/usr/local/lib/libboost_regex.so;
$TARGET_FS/usr/local/lib/libboost_date_time.so;
$TARGET_FS/usr/local/lib/libboost_filesystem.so;
$TARGET_FS/usr/local/lib/libboost_program_options.so;
$TARGET_FS/usr/local/lib/libboost_system.so;
$TARGET_FS/usr/local/lib/libboost_signals.so;
$TARGET_FS/usr/local/lib/libboost_thread.so;
pthread
Boost Includes Found: $TARGET_FS/usr/local/include
COMPILER IS is /usr/bin/arm-linux-gnueabi-g++-4.6
CMAKE_BUILD_TYPE is optimized
Building HAL, platform is: X86
-- Found PROTOBUF: $TARGET_FS/usr/local/lib/libprotobuf.so
-- Looking for include files CMAKE_HAVE_PTHREAD_H
-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CRYPTO++
linked by target "<target_1>" in directory <directory_1>
DUMBNET
linked by target "<target_2>" in directory <directory_2>
JSONCPP
linked by target "<target_3>" in directory <directory_3>
NET
linked by target "<target_4>" in directory <directory_4>
SNMP_LIB
linked by target "<target_5>" in directory <directory_5>
UHD
linked by target "<target_6>" in directory <directory_6>
编辑 2(已解决?)
刚刚发生了一些奇怪的事情:我完全确定我已经尝试过了,但是现在将目标文件系统的根目录设置为TARGET_FS
(既不附加/usr
也不/usr/local
附加)允许 cmake 找到所有必需的路径。可能是以前的一些 cmake 运行残留缓存阻止了它的工作?