CMake:在</pthread.h>中找不到<pthread.h>

时间:2012-11-04 12:47:00

标签: windows header include pthreads cmake

我是CMake的新手。我在Linux上测试了我正在制作的程序。这个程序使用(POSIX Threads lib),所以在我的CMakeList中,我添加了:

find_package(Threads)

它适用于Linux发行版(Arch,Mint,Ubuntu,...),但现在,我正在Windows32(Visual Studio 9 2008)中尝试它,我在生成期间收到此消息:

-- Looking for include file pthread.h - not found

(当我编译输出项目文件时,确实找不到pthread.h。)

在Windows上,考虑“C:\ pthread”作为我的pthread目录,我在路径中定义:

  • “C:\ pthread \ include”(其中有着名的“pthread.h”)
  • “C:\ pthread \”(在CMake某处寻找“包含”的情况下)

但我仍然得到相同的错误(即使在删除缓存后)。我知道我可以在我的Project中“手动”添加Pthread,或者在CMakeList.txt中定义一些常量,但我认为这不是CMake的原理:我可以在所有系统上使用SAME“CMakeList.txt”,对吧?那么我怎么能告诉CMake“嘿!看这里!Pthread就在这个目录中!”。 也许Cmake没有查看PATH,但在另一个环境变量中,但我没有找到这些信息。

感谢您的阅读。

编辑:我不知道它是否有所作为,但我的项目是一个C ++项目(而不是C)

2 个答案:

答案 0 :(得分:3)

我做了什么,我编辑了cmake文件:

option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)

option(gtest_disable_pthreads "Disable uses of pthreads in gtest." ON)

(我正在使用谷歌测试)

答案 1 :(得分:1)

据我所知,Pthreads在Windows平台上本身不受支持。除非你使用像

这样的东西

win services for unix

Windows只有win32线程。

但是,这是一个在Windows上提供pthread的项目

pthreads on win32