CMake的FindThreads.cmake不会找到我的pthreads.h头 [英] CMake FindThreads.cmake won't find my pthreads.h header

查看:6065
本文介绍了CMake的FindThreads.cmake不会找到我的pthreads.h头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Android的cmake的来编译应用程序Android系统。这实质上创建使用提供Android的NDK工具链CMake的工具链文件。

I'm using android-cmake to compile an application for Android. This essentially creates a CMake toolchain file for using the toolchain provided with Android's NDK.

this相关的问题,我遇到了我的CMakeLists.txt文件中的以下行的问题:

As with this related question, I'm having problems with the following line in my CMakeLists.txt file:

find_package(Threads REQUIRED)

头文件位于

~/Android/android-ndk-r7/platforms/android-8/arch-arm/usr/include/pthread.h

该库文件位于

~/Android/android-ndk-r7/platforms/android-8/arch-arm/usr/lib/libthread_db.so

问题是,FindThreads.cmake调用 CHECK_INCLUDE_FILES(pthreads.h中,CMAKE_HAVE_PTHREAD_H)这似乎不打扰在该目录检查。

The problem is that FindThreads.cmake calls CHECK_INCLUDE_FILES("pthread.h", CMAKE_HAVE_PTHREAD_H) and this seems to not bother to check in that directory.

CMAKE_INCLUDE_PATH 的CMake的有用的一些变量wiki页面$ C>允许标题搜索路径的设置, CMAKE_LIBRARY_PATH 允许库搜索路径的设置, CMAKE_ preFIX_PATH 似乎是find_package同时提供。

According to CMake's Useful Variables wiki page CMAKE_INCLUDE_PATH allows the setting of the header search path, CMAKE_LIBRARY_PATH allows setting of the library search path, and CMAKE_PREFIX_PATH seems provide both for find_package.

不过,尽管我是否在运行前设置环境变量的CMake ...

However, despite whether I set environment variables before running cmake...

export CMAKE_INCLUDE_PATH=~/Android/android-ndk-r7/platforms/android-8/arch-arm/usr:~/Android/android-ndk-r7/platforms/android-8/arch-arm/usr/include

...还是我直接的CMakeLists.txt设置它们...

... or whether I set them directly in CMakeLists.txt...

if(ANDROID)
    set(CMAKE_INCLUDE_PATH
        ${ANDROID_NDK_SYSROOT}/usr
        ${ANDROID_NDK_SYSROOT}/usr/include
        ${CMAKE_INCLUDE_PATH}
    )

    set(CMAKE_LIBRARY_PATH
        ${ANDROID_NDK_SYSROOT}/usr
        ${ANDROID_NDK_SYSROOT}/usr/lib
        ${CMAKE_LIBRARY_PATH})

    set(CMAKE_PREFIX_PATH
        ${ANDROID_NDK_SYSROOT}
        ${CMAKE_PREFIX_PATH})

    message(${ANDROID_NDK_SYSROOT})
    message(${CMAKE_INCLUDE_PATH})

endif()

find_package(Threads REQUIRED)

...(这确实得到执行,这些消息被打印),并在 $ {ANDROID_NDK_SYSROOT} 包含

/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm

我仍然得到消息

找不到线程(丢失:Threads_FOUND)

Could NOT find Threads (missing: Threads_FOUND)

没有任何人有任何建议,我在做什么错了?

Does anybody have any suggestions as to what I am doing wrong?

推荐答案

我发现了很多调试后解决了这个问题,这是相当奇怪的。从本质上讲,FindThreads.cmake调用一个名为 CHECK_INCLUDE_FILES 宏它试图 TRY_COMPILE 源文件,该文件只是包含头文件的 CHECK_INCLUDE_FILES 宏提供。

I found the solution to this problem after a lot of debugging and it's quite strange. Essentially, FindThreads.cmake calls a macro called CHECK_INCLUDE_FILES which tries to TRY_COMPILE a source file which simply includes the headers that the CHECK_INCLUDE_FILES macro is provided with.

请注意,它并使用 CMAKE_REQUIRED_INCLUDES 由@sakra建议所以这是很有用的。

Note that it does use CMAKE_REQUIRED_INCLUDES as suggested by @sakra so that's useful.

使用Android的CMake的,在 TRY_COMPILE 宏试图编译从NDK臂Linux的androideabi-gcc编译器与所有指定的编译标志。该android.toolchain.cmake文件包含的一些设置,这些编译标志下面几行:

Using android-cmake, the TRY_COMPILE macro tries to compile with the arm-linux-androideabi-gcc compiler from the NDK with all of the specified compile flags. The android.toolchain.cmake file contains the following lines that set some of these compile flags:

if( BUILD_WITH_ANDROID_NDK )
 set( CMAKE_CXX_FLAGS "--sysroot=\"${ANDROID_NDK_SYSROOT}\" ${CMAKE_CXX_FLAGS}" )
 set( CMAKE_C_FLAGS "--sysroot=\"${ANDROID_NDK_SYSROOT}\" ${CMAKE_C_FLAGS}" )

该TRY_COMPILE宏失败,因为按照CMakeError.log文件包含以下内容:

The TRY_COMPILE macro fails and as per the CMakeError.log file contains the following:

Run Build Command:/opt/local/bin/gmake "cmTryCompileExec/fast"
/opt/local/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make CMakeFiles/cmTryCompileExec.dir/build
gmake[1]: Entering directory '/Users/martin/Repositories/Delta/build/android/CMakeFiles/CMakeTmp'
"/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_progress_report /Users/martin/Repositories/Delta/build/android/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec.dir/CheckIncludeFiles.c.o
/Users/martin/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc   --sysroot=;/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm" -fPIC -DANDROID -Wno-psabi -fsigned-char -mthumb -march=armv7-a -mfloat-abi=softfp  " -I/Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include -I/Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include -I/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm/usr -I/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm/usr/include   -o CMakeFiles/cmTryCompileExec.dir/CheckIncludeFiles.c.o   -c /Users/martin/Repositories/Delta/build/android/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
arm-linux-androideabi-gcc: no input files

如果您滚动到实际的编译器线(第二次从底部)右侧可以看到 - SYSROOT =; / ... 部分。即使CMake的线以上使用转义字符串,CMake的已经变成该第一逃脱报价成分号和留在第二作为正常报价,从而在SYSROOT线分号,然后一个字符串包含所有CMAKE_CXX_FLAGS事后(易看到SO的语法高亮)。

If you scroll to the right on the actual compiler line (second from the bottom) you can see the --sysroot=;/... section. Even though the CMake lines above use escaped strings, CMake has turned this first escaped quotation into a semicolon and left the second as a normal quotation, resulting in a semicolon in the sysroot line and then a string literal containing all the CMAKE_CXX_FLAGS afterwards (easy to see with SO's syntax highlighting).

此的解决方案是修改android.toolchain.cmake以除去逃过报价,因为它们是不必要的。

The solution to this is to modify android.toolchain.cmake to remove the escaped quotations as they are unnecessary.

if( BUILD_WITH_ANDROID_NDK )
 set( CMAKE_CXX_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT} ${CMAKE_CXX_FLAGS}" )
 set( CMAKE_C_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT} ${CMAKE_C_FLAGS}" )

这篇关于CMake的FindThreads.cmake不会找到我的pthreads.h头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆