gpt4 book ai didi

Cmake 找不到带有神秘错误消息的 Threads 包

转载 作者:行者123 更新时间:2023-12-05 05:22:31 28 4
gpt4 key购买 nike

我正在尝试使用以下 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 的 raspberry 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 是否丢失了某些东西,或者我应该得到一个丢失的包?

最佳答案

使用你的代码我可以重现你的错误,这似乎是一个后续错误:

-- 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.

两种可能的解决方案:

  1. C 添加到您的项目语言中:

    project(MotionBlow C CXX)
  2. .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

引用资料

关于Cmake 找不到带有神秘错误消息的 Threads 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40361522/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com