MJHD

エモさ駆動開発

Mac上のcmakeにて,Boost::ThreadやThread::Threadを使おうとすると「Could NOT find Threads (missing: Threads_FOUND)」と言われる

cmakeを使ってBoost::Threadを使用するプロジェクトのMakefileを作成しようとしたところ,初回は以下のエラーが,

CMake Error at /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/CheckIncludeFiles.cmake:79 (try_compile):
  Unknown extension ".c" for file

    /Users/mjhd/Projects/trax-stable/trax-viewer/CMakeFiles/CMakeTmp/CheckIncludeFiles.c

  try_compile() works only for enabled languages.  Currently these are:

    CXX

  See project() command to enable other languages.
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindThreads.cmake:123 (CHECK_INCLUDE_FILES)
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/CMakeFindDependencyMacro.cmake:65 (find_package)
  cmake/FindBoost.cmake:1401 (find_dependency)
  CMakeLists.txt:22 (find_package)


-- Looking for include file pthread.h - not found
CMake Error at /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/CMakeFindDependencyMacro.cmake:65 (find_package)
  cmake/FindBoost.cmake:1401 (find_dependency)
  CMakeLists.txt:22 (find_package)

二回目以降は以下のエラーが,

CMake Error at /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/CMakeFindDependencyMacro.cmake:65 (find_package)
  cmake/FindBoost.cmake:1401 (find_dependency)
  CMakeLists.txt:22 (find_package)

表示されるようになった.
しかも,この現象が起こるのはMac上のcmakeだけ

解決策

2日間悩んだ挙句,解決策を発見した.

project(YOUR_PROJECT CXX)

などと書いてある部分を,

project(YOUR_PROJECT CXX C)

と変更し,CMakeFilesディレクトリ,CMakeCache.txtファイルなどを削除してから,再びcmake .を行う.(重要)