与this related question一样,我在CMakeLists.txt文件中遇到以下行问题:
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(“pthread.h”,CMAKE_HAVE_PTHREAD_H),这似乎无需检查该目录.
根据CMake’s Useful Variables wiki page,CMAKE_INCLUDE_PATH允许设置头搜索路径,CMAKE_LIBRARY_PATH允许设置库搜索路径,CMAKE_PREFIX_PATH似乎同时为find_package提供.
但是,尽管我在运行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中设置它们……
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
我仍然得到消息
Could NOT find Threads (missing: Threads_FOUND)
有人对我做错了什么有任何建议吗?
解决方法
请注意,它确实使用了@sakra建议的CMAKE_required_INCLUDES,因此非常有用.
使用android-cmake,TRY_COMPILE宏尝试使用带有所有指定编译标志的NDK中的arm-linux-androideabi-gcc编译器进行编译. android.toolchain.cmake文件包含以下行,用于设置其中一些编译标志:
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文件包含以下内容:
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的语法突出显示).
对此的解决方案是修改android.toolchain.cmake以删除转义的引用,因为它们是不必要的.
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}" )
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。