Mei*_*zel 4 c kdevelop cmake cross-compiling angstrom-linux
我的cmake交叉编译器项目遇到了奇怪的问题.
我找到了自己的库,但没有找到我工具链中的(系统)库.
以前我在debian挤压机上使用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")
Run Code Online (Sandbox Code Playgroud)
这是尝试使用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
Run Code Online (Sandbox Code Playgroud)
所以找到了LIBS_TEST.但不是libm或libpthread.我尝试了不同的项目:我找到了所有的库,但没有找到"系统"库.
我已经尝试过不同的东西了
set(CMAKE_FIND_LIBRARY_PREFIXES lib )
set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
Run Code Online (Sandbox Code Playgroud)
还有一些我不记得的事情.
当我手动指定目录时,唯一正在工作的是:
find_library(ASTLIBS_M NAMES m PATHS /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib)
Run Code Online (Sandbox Code Playgroud)
在指定了我之后CMakeLists.txt,找到了库,我可以编译我的项目而没有任何错误.
但是:这不是我想要的,因为我有很多项目和很多图书馆,我不想编辑所有我CMakeLists.txt...... :(
有没有人知道是什么让我的旧机器找到了系统库而没有在我的IDE/CMake文件中指定任何特殊内容?
编辑: 我刚注意到我的一个可执行文件在Linker阶段它抛出了一些错误,它无法从glibc找到一些符号 - 似乎我的debian wheezy系统有更多错误. - 我希望我能搞清楚......
编辑:
Cla*_*dio 14
你有没有尝试过使用工具链文件?我也交叉编译到ARM和AVR 很多,它没有麻烦(我也使用KDevelop,它与CMake一起很好地工作).重点是通过CMAKE_FIND_ROOT_PATH变量指定工具链根文件系统的路径.尝试将所有这些放在一个文件中,我通常在我交叉编译的架构之后命名(在这种情况下我称之为arm-unknown-linux-gnueabi.cmake):
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Linux)
# which C and C++ compiler to use
SET(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /home/claudio/TS-7400/rootfs)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
Run Code Online (Sandbox Code Playgroud)
请注意,变量CMAKE_FIND_ROOT_PATH_MODE_xxx变量控制CMake将在何处查找二进制文件,库和头文件.我通常将PROGRAM设置为,NEVER因此它永远不会使用跨架构根文件系统中的二进制文件,因为它们无论如何都不会在主机上运行.对于库和头文件BOTH意味着它将首先搜索您指定的ROOT_PATH,然后如果找不到它将通过您的主机系统dirs.
这样,每当你想要交叉编译一个项目时,你所要做的就是创建一个构建目录(所以它不会将你的源与构建期间创建的文件混合在一起),然后从那里运行cmake,指定你想要的工具链文件使用(我假设你CMakeLists.txt的源码所在的同一目录上的你的工具链文件 - 在我的例子中是project_sources_dir):
cd project_sources_dir
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../arm-unknown-linux-gnueabi.cmake ..
Run Code Online (Sandbox Code Playgroud)
使用工具链文件的重点是,如果要为主机编译完全相同的项目,则不必更改单个行CMakeLists.txt.只需运行cmake而不指定工具链文件:
cd project_sources_dir
mkdir build
cd build
cmake ..
Run Code Online (Sandbox Code Playgroud)
并且您的项目已准备好为您的主机编译本机.如果还不够,可以在CMake交叉编译中查找更多详细信息
CMake 的模块搜索某些默认路径find_library。如果您的旧机器上的系统库恰好位于这样的位置,则无需执行任何其他工作即可找到它们。
但是,由于您的新计算机的这些库的路径似乎是“/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib”,因此您需要告诉 CMake 有关这一点的信息。
一种这样的方法,正如您所展示的那样(显式添加路径)。但在这种情况下,该路径可能仅特定于该机器 - 因此您最好仅在该机器上调用 CMake 时设置该路径。您可以将其添加到CMAKE_PREFIX_PATH例如:
cmake . -DCMAKE_PREFIX_PATH=/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr
Run Code Online (Sandbox Code Playgroud)
(注意:在这种情况下,路径在find_library调用时会附加“lib”)。
或者,如果您只想影响find_library搜索路径,而不是所有 find_xxx模块,请设置CMAKE_LIBRARY_PATH
cmake . -DCMAKE_LIBRARY_PATH=/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib
Run Code Online (Sandbox Code Playgroud)