morynicz
morynicz

Reputation: 2342

Cmake failed to find Threads package with cryptic error message

I'm trying to configure with following 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)

On ubunutu 16.04 it works ok, but both on raspberry pi with Raspbian 8.0/Cmake 3.6.2 and on ubuntu 15.10/Cmake 3.2.2 I get

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)

Unfortunately, error log contains only this:

Determining if files pthread.h exist failed with the following output:

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


int main(void){return 0;}

So I have no idea how to get this fixed. Any ideas? Is my CMakelists.txt missing something or should I get a missing package?

Upvotes: 3

Views: 10713

Answers (1)

Florian
Florian

Reputation: 43030

Taking your code I could reproduce your error and it seems to be a follow-up error from this:

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

Two possible solutions:

  1. Add C to your project languages:

    project(MotionBlow C CXX)
    
  2. Add .c extension a valid C++ file:

    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)
    

If none of this works, check that pthread is installed:

sudo apt-get install libpthread-stubs0-dev

References

Upvotes: 2

Related Questions