【问题标题】:Windows7 pthread.h not found未找到 Windows7 pthread.h
【发布时间】:2012-11-21 02:50:48
【问题描述】:

我正在尝试使用 cmake 在 Windows 中编译 libaws (http://sourceforge.net/projects/libaws/) 库。我已经包含了 openssl、libxml、libcurl,我正在使用这个命令行。

C:\libaws>cmake -G "Visual Studio 10" -DCURL_LIBRARY="C:\tools\curl-7.28.1\lib" -DCURL_INCLUDE_DIR="C:\tools\curl-7.28.1\include" -DLIBXML2_LIBRARIES="C:\tools\libxml22.7.8.win32\lib" -DLIBXML2_INCLUDE_DIR="C:\tools\libxml2-2.7.8.win32\include" -DPTHREAD_INCLUDE_DIR="C:\tools\pthread\include"  ..\tools\libaws-0.9.2
--    

它会抛出以下错误:

-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CURL: C:/tools/curl-7.28.1/lib (found version "7.28.1")
-- Found OpenSSL: optimized;C:/openssl/lib/ssleay32.lib;debug;C:/openssl/lib/ssleay32.lib;optimized;C:/openssl/lib/libeay32.lib;debug;C:/openssl/lib/libeay32.lib (found version "1.0.1c")
-- Found LibXml2: C:/tools/libxml2-2.7.8.win32/lib (found version "2.7.8")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found.

CMakeLists.txt:78 (MESSAGE) 处的 CMake 错误: 找不到 pthread 开发头文件

我在 C:\tools\pthread\include 中包含了 ptherad.h、semaphore.h 等,并提供了命令行标志:-DPTHREAD_INCLUDE_DIR="C:\tools\pthread\include"。在我的 CMakeLists.txt 中,我添加了

INCLUDE_DIRECTORIES(${PTHREAD_INCLUDE_DIR})

有什么想法吗?

【问题讨论】:

  • 我不知道答案,但我猜“P-Thread”中的“P”可能与它有关
  • 我没听懂你。你指的是哪里?
  • “P”代表 POSIX。 Windows 不是 POSIX 系统,因此大多数编译器不会在 Windows 上附带基于 POSIX 的 API 是有道理的。
  • 我不明白 - 你接受了一个表明你没有 pthread.h 的答案,但你清楚地告诉编译器(和我们)它在 c:\tools\pthread\include 中 - 确实你只是弥补?顺便说一句,您可以在这里获得 Windows 的 pthread 实现:sourceware.org/pthreads-win32
  • 我认为问题在于线程的 CMake 查找模块假设您在使用 Visual Studio 时没有使用 pthreads,并且需要修复以使其正常工作。我记得大约两周前有人在这里问过类似的 pthreads + cmake + Visual Studio 问题。 stackoverflow.com/questions/13218646/…

标签: c++ windows cmake pthreads


【解决方案1】:

Visual Studio 不附带“pthread”实现。我猜你需要使用另一个编译器,比如 MinGW。

@jens-a-koch 是对的:我的回答不应该被接受!请“不接受”,以便我删除它。

我相信您的 CMake 查找模块可能没有使用 PTHREAD_INCLUDE_DIR 定义(类似于@drescherjm 所说的)。

【讨论】:

  • 这不应该是公认的答案。这与 VisualStudio/VC 或 Mingw 提供“pthread”的实现无关。问题是 CMake 在作为外部依赖项安装时不会检测 pthread - 即使设置了正确的包含路径。
猜你喜欢
  • 2012-10-24
  • 2014-09-30
  • 1970-01-01
  • 2017-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
相关资源
最近更新 更多