我在我的cmake交叉编译项目中遇到了奇怪的问题。
我的自己的库能被找到,但是我的工具链(系统)库找不到。
之前我在Debian Squeeze机器上使用KDevelop。现在我在新的Debian Wheezy机器上配置失败了。它找不到像m
或pthread
这样的系统库。
在我的旧机器上,以下内容完美地运行,但我不记得我有做过什么特别的事情来使其工作。
以下是我的一个CMakeLists.txt
文件之一
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 2.6.36.4)
SET(CMAKE_C_COMPILER arm-angstrom-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER arm-angstrom-linux-gnueabi-g++)
include_directories(../include
../../../sample/include)
project(testmain)
add_executable(testmain
some_c-source-file.c)
set(CMAKE_LIBRARY_PATH ../lib/arm-26/lib
../../../sample/lib/arm-26/lib)
find_library(LIBS_TEST NAMES akku)
find_library(LIBS_M NAMES m)
find_library(LIBS_PTHREAD NAMES pthread )
target_link_libraries(akkumain
${LIBS_TEST}
${LIBS_M}
${LIBS_PTHREAD})
set(CMAKE_C_FLAGS "-Wall -Werror")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O2 -rdynamic")
set(CMAKE_C_FLAGS_RELEASE "-g0 -O0")
set(CMAKE_CXX_FLAGS "-Wall -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O2 -rdynamic")
set(CMAKE_CXX_FLAGS_RELEASE "-g0 -O0")
这是在使用KDevelop编译时显示的消息:(重申一下:这在我的旧机器上可以工作)
/home/user/testmain/build> /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug /home/user/testmain/
-- The C compiler identification is GNU 4.3.3
-- The CXX compiler identification is GNU 4.3.3
-- Check for working C compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc
-- Check for working C compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
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:
LIBS_M
linked by target "akkumain" in directory /home/user/testmain
LIBS_PTHREAD
linked by target "akkumain" in directory /home/user/testmain
我已经发现了LIBS_TEST。但是没有找到libm
或libpthread
。
我尝试过不同的项目:所有我的库都被找到了,但是没有找到“系统”库。
我已经尝试了不同的方法,比如
set(CMAKE_FIND_LIBRARY_PREFIXES lib )
set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
还有一些我不记得的东西。
唯一有效的方法是手动指定目录:
find_library(ASTLIBS_M NAMES m PATHS /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib)
在我的
CMakeLists.txt
中指定后,库被找到了,并且我可以编译我的项目而没有任何错误。但是:这不是我想要的,因为我有很多项目和许多库,我不想编辑所有的
CMakeLists.txt
... :(有人知道是什么让我的旧机器在IDE/CMake文件中没有特别指定时找到了系统库吗?
编辑: 我刚刚注意到,对于我的一个可执行文件,在链接器阶段会抛出一些找不到glibc符号的错误 - 似乎我的debian wheezy系统还有其他问题。-我希望我能解决它...
编辑:
也许我应该简单总结一下:我的代码编译得很好,但是我的工具链中的所有库都找不到,但是如果我手动添加工具链库的路径,则编译通过,但在链接器阶段失败。