我正在尝试配置以下CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(MotionBlow CXX)
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS system program_options REQUIRED)
include(gtest.cmake)
add_executable(motionBlow src/blow.cpp)
target_include_directories(motionBlow PUBLIC include)
target_link_libraries(motionBlow RTIMULib ${Boost_LIBRARIES})
set_property(TARGET motionBlow PROPERTY CXX_STANDARD 14)
add_executable(chat_client src/chat_client.cpp)
target_include_directories(chat_client PUBLIC include)
target_link_libraries(chat_client ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_client PROPERTY CXX_STANDARD 14)
add_executable(chat_server src/chat_server.cpp)
target_include_directories(chat_server PUBLIC include)
target_link_libraries(chat_server ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_server PROPERTY CXX_STANDARD 14)
enable_testing()
add_executable(matrixTest test/MatrixTest.cpp src/Matrix.cpp)
target_include_directories(matrixTest PUBLIC include ${GTEST_INCLUDE_DIR})
target_link_libraries(matrixTest ${GTEST_LIBRARY} Threads::Threads)
set_property(TARGET matrixTest PROPERTY CXX_STANDARD 14)
在ubunutu 16.04上它运行正常,但是在Raspbian 8.0 / Cmake 3.6.2的覆盆子pi和ubuntu 15.10 / Cmake 3.2.2上我得到了
CMake Error at /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.2/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
不幸的是,错误日志只包含这个:
Determining if files pthread.h exist failed with the following output:
Source:
/* */
#include <pthread.h>
int main(void){return 0;}
所以我不知道如何解决这个问题。有任何想法吗?我的CMakelists.txt是否遗漏了某些内容,或者我是否应该找不到包裹?
答案 0 :(得分:2)
接受你的代码我可以重现你的错误,这似乎是一个后续错误:
-- Looking for include file pthread.h
CMake Error at /usr/share/cmake-3.2/Modules/CheckIncludeFiles.cmake:74 (try_compile):
Unknown extension ".c" for file
try_compile() works only for enabled languages. Currently these are:
CXX
See project() command to enable other languages.
两种可能的解决方案:
将C
添加到您的项目语言中:
project(MotionBlow C CXX)
将.c
扩展名添加为有效的C ++文件:
<强> MotionBlowMakeRulesOverwrite.cmake 强>
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS c)
<强>的CMakeLists.txt 强>
cmake_minimum_required(VERSION 3.2)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "MotionBlowMakeRulesOverwrite.cmake")
project(MotionBlow CXX)
如果这些都不起作用,请检查是否已安装pthread
:
sudo apt-get install libpthread-stubs0-dev
<强>参考强>