CMake无法使用Linaro工具链找到线程

时间:2015-08-28 21:25:31

标签: cmake pthreads cross-compiling linaro

我无法让CMake找到带有Linaro ARM工具链的线程(我尝试了几种不同的工具)。这就是我所做的:

我创建了一个 Toolchain-Linaro-arm.cmake 文件,如下所示:

set (CMAKE_SYSTEM_NAME Linux)                                                                           

include (CMakeForceCompiler)                                                                            
set (TOOLCHAIN_BASE "/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf/")                          

set (CMAKE_SYSTEM_PROCESSOR armhf-cortexa9)                                                             

CMAKE_FORCE_C_COMPILER("${TOOLCHAIN_BASE}/bin/arm-linux-gnueabihf-gcc" GNU)                             
CMAKE_FORCE_CXX_COMPILER("${TOOLCHAIN_BASE}/bin/arm-linux-gnueabihf-g++" GNU)                           

set (CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} /home/user/sysroot)                                   

set (CMAKE_SIZEOF_VOID_P 4)                                                                             

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)

我创建了一个使用线程的最小示例项目:

~/threadstest $ ls
CMakeLists.txt main.cpp

~/threadstest $ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(threads_test)
add_executable(test main.cpp)
find_package(Threads REQUIRED)
target_link_libraries(test, ${CMAKE_THREAD_LIBS_INIT})

~/threadstest $ cat main.cpp
int main() { }

~/threadstest $ mkdir build; cd build

~/threadstest/build $ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-Linaro-arm.cmake ..
CMake Error at /opt/cmake-3.3.1-Linux-x86_64/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /opt/cmake-3.3.1-Linux-x86_64/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /opt/cmake-3.3.1-Linux-x86_64/share/cmake-3.3/Modules/FindThreads.cmake:205 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:8 (find_package)

~/threadstest/build $ cat CMakeFiles/CMakeError.log

Determining if files pthread.h exist failed with the following output:
Change Dir: /home/user/threadstest/arm/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_37a3c/fast"
/usr/bin/make -f CMakeFiles/cmTC_37a3c.dir/build.make CMakeFiles/cmTC_37a3c.dir/build
make[1]: Entering directory `/home/user/threadstest/arm/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_37a3c.dir/CheckIncludeFiles.c.o
/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc    -o CMakeFiles/cmTC_37a3c.dir/CheckIncludeFiles.c.o   -c /home/user/threadstest/arm/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc)
make[1]: Leaving directory `/home/user/threadstest/arm/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTC_37a3c.dir/CheckIncludeFiles.c.o] Error 1
make: *** [cmTC_37a3c/fast] Error 2

Source:
/* */
#include <pthread.h>


int main(void){return 0;}

我知道pthread库存在:

$ find ~/sysroot -name "*pthread*"
/home/user/sysroot/usr/lib/libpthread_nonshared.a
/home/user/sysroot/usr/lib/libpthread.so.0
/home/user/sysroot/usr/lib/libpthread-2.19-2014.08-1-git.so
/home/user/sysroot/usr/lib/libpthread_p.a
/home/user/sysroot/usr/lib/libpthread.a
/home/user/sysroot/usr/lib/libpthread.so
/home/user/sysroot/usr/include/bits/pthreadtypes.h
/home/user/sysroot/usr/include/pthread.h

看起来有些东西仍在查看我的原生libc,而不是交叉编译环境:

  

/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc -o CMakeFiles / cmTC_37a3c.dir / CheckIncludeFiles.co -c / home / user / threadstest /臂/ CMakeFiles / CMakeTmp / CheckIncludeFiles.c       /opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc: /lib/x86_64-linux-gnu/libc.so.6:< / em>版本“GLIBC_2.14”未找到(/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc所需)

1 个答案:

答案 0 :(得分:1)

问题的根本原因不在pthread库中:

根本原因是:

  

/lib/x86_64-linux-gnu/libc.so.6:版本`GLIBC_2.14&#39;未找到(需要/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc)

您的编译器正在尝试使用您的本地libc

1)在下载的sysroot中找到libc.so *并使用以下命令检查版本:

objdump -p libc.so.6  | grep "Version References:" -A 10

如果一切正常,请使用此lib(使用--sysroot选项);

您可以尝试手动执行此操作:

  

/opt/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf//bin/arm-linux-gnueabihf-gcc -o CMakeFiles / cmTC_37a3c.dir / CheckIncludeFiles.co -c / home / user / threadstest / arm / CMakeFiles / CMakeTmp / CheckIncludeFiles.c --sysroot / home / user / sysroot /

2)您的工具链可能使用与系统上安装的libc.so版本不同的版本编译,在您的系统上下载适当的版本并使用它。