我正在为一个基于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
中对编译器的提示约为${TARGET_FS}/usr/local/lib
,所以我有点期待这种行为)。我需要一种方法来指定CMAKE_FIND_ROOT_PATH
的多个路径,但是简单地用空格分隔它们并将它们用双引号括起来似乎不是可行的方法(SET(CMAKE_FIND_ROOT_PATH "${TARGET_FS}/usr/local ${TARGET_FS}/usr")
)。
有没有人对如何面对这个问题有任何暗示?
编辑回复sergey的评论
当前设置提供此输出
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
也没有{{1} })允许cmake找到所有必需的路径。它可能是一些以前的cmake运行剩余缓存阻止它工作?
答案 0 :(得分:0)
我选择了类似的东西并指定了搜索路径。您可以指向交叉编译库的路径。
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
/lib
/usr/lib
/usr/lib/arm-linux-gnueabihf
/usr/local/lib)
find_library(LIBSSL NAMES libssl.so PATHS)
add_executable(myapp ${myapp_SRC} )
if(LIBSSL )
message(STATUS ${LIBSSL})
target_link_libraries(myapp
${LIBSSL} )
else()
message(FATAL_ERROR "FATAL ERROR: missing library")
endif()