CMake:< pthread.h>在Windows中找不到 [英] CMake : <pthread.h> not found in Windows

查看:6139
本文介绍了CMake:< pthread.h>在Windows中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  find_package(Threads)

它适用于Linux系统(Arch,Mint,Ubuntu,...),但现在, Windows 32(Visual Studio 9 2008),我在生成期间收到此消息:

   - 查找包含文件pthread.h  - 未找到

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

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




  • C:\pthread\include(其中存在着名的pthread.h)

  • C:\pthread\



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



感谢您阅读。 p>

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

解决方案

显然, CMAKE_USE_WIN32_THREADS_INIT 在所有平台的上下文中都很有用。这个变量是在调用findPackage(Threads)时生成或初始化的,理想情况下它会处理所有平台上的链接问题,以防线程库需要链接到可执行文件。基本上,它在平台unix类似的平台上生成适当的线程库名称,并且在诸如windows之类的平台上是空的,其中不需要显式线程库来链接。
参考:CMake findThreads https:// cmake .org / cmake / help / v3.0 / module / FindThreads.html?highlight = threads


I'm newbie with CMake. I tested it on Linux for a program I am making. This program uses (POSIX Threads lib), so in my CMakeList, I added :

find_package(Threads)

It works on Linux distribs (Arch, Mint, Ubuntu, ...), but now, I'm trying it in Windows32 (Visual Studio 9 2008), and I get this message during generation :

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

(and when I compile output project file, pthread.h is indeed not found).

On Windows, considering "C:\pthread" as my pthread directory, I defined in path :

  • "C:\pthread\include" (where resides the famous "pthread.h")
  • "C:\pthread\" (in the case where CMake looks for an "include" somewhere)

But I still get the same error (even after deleted cache). I know I could "manually" add Pthread in my Project, or define some constants in CMakeList.txt, but I thinks it's not the principle of CMake : I could use the SAME "CMakeList.txt" on all systems, right ? So how can I tell to CMake "Hey ! Looks here ! Pthread is in this directory !". Maybe Cmake doesn't look in PATH, but in another environment variable, but I didn't find this information.

Thank you for reading.

EDIT : I don't know if it makes a difference, but my project is a C++ project (not C)

解决方案

Apparently the CMAKE_USE_WIN32_THREADS_INIT is useful in context of all platforms. This variable is generated or initialised on invocation of findPackage(Threads), ideally it handles linking issues on all platforms in case thread library is required to be linked with executable. Basically it generates appropriate thread library name on platform unix like platforms and is empty on platform such as windows where explicit threading library is not required for linking. Reference: CMake findThreads https://cmake.org/cmake/help/v3.0/module/FindThreads.html?highlight=threads

这篇关于CMake:< pthread.h>在Windows中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆