C语言 如何在windows上设置pthreads?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19467455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:45:35  来源:igfitidea点击:

How to set up pthreads on windows?

cwindowspthreadsmingw

提问by tmeloliveira

I found an implementation for pthreads on Windows here, but I couldn't get it to work right. Can anyone help me to install pthreads ? Like where to put DLLs, .lib, and .h files?

我在这里找到了 Windows 上 pthreads 的实现,但我无法让它正常工作。有人可以帮我安装 pthreads 吗?比如将 DLL、.lib 和 .h 文件放在哪里?

Also, as an environment I'm not using Visual Studio, but Codeblocks with Mingw.

另外,作为一个环境,我没有使用 Visual Studio,而是使用带有 Mingw 的代码块。

I usually develop on Linux, but this project has to be on Windows, and I've already got some code implemented using pthreads, so I don't want to use Windows Threads from 'windows.h'.

我通常在 Linux 上开发,但这个项目必须在 Windows 上,而且我已经使用 pthreads 实现了一些代码,所以我不想使用 'windows.h' 中的 Windows 线程。

回答by Siddhartha Ghosh

The .dll can go in any directory listed in your PATH environment variable.

.dll 可以放在 PATH 环境变量中列出的任何目录中。

The .lib file can go in any directory listed in your LIB environment variable.

.lib 文件可以放在 LIB 环境变量中列出的任何目录中。

The .h files can go in any directory listed in your INCLUDE environment variable.

.h 文件可以放在 INCLUDE 环境变量中列出的任何目录中。

Also see the FAQspage of the link you shared .

另请参阅您共享的链接的常见问题解答页面。

Read Q6, Q7, Q8.

阅读 Q6、Q7、Q8。

回答by winux

For Visual C++ Users (not MingW), follow this steps:

对于 Visual C++ 用户(不是 MingW),请按照以下步骤操作:

1) download "ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip"

1) 下载“ ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip

2) in the extraction folder, open the subfolder "Pre-built.2" and you should see the following files:

2) 在解压文件夹中,打开子文件夹“Pre-built.2”,你应该看到以下文件:

  • "Pre-built.2\dll\x64\pthreadVC2.dll" OR "Pre-built.2\dll\x86\pthreadVC2.dll"
  • "Pre-built.2\lib\x64\pthreadVC2.lib" OR "Pre-built.2\lib\x86\pthreadVC2.lib"
  • "Pre-built.2\include\pthread.h"
  • "Pre-built.2\include\sched.h"
  • "Pre-built.2\include\semaphore.h"
  • “Pre-built.2\dll\x64\pthreadVC2.dll”或“Pre-built.2\dll\x86\pthreadVC2.dll”
  • “Pre-built.2\lib\x64\pthreadVC2.lib”或“Pre-built.2\lib\x86\pthreadVC2.lib”
  • "Pre-built.2\include\pthread.h"
  • "Pre-built.2\include\sched.h"
  • "Pre-built.2\include\semaphore.h"

3) For Visual Studio C++ x64 projects, go to project properties and add the following paths accordingly:

3) 对于 Visual Studio C++ x64 项目,转到项目属性并相应地添加以下路径:

  • Additional lib Files add "yourpath\Pre-built.2\lib\x64\"
  • Additional dll files add "yourpath\Pre-built.2\dll\x64\"
  • Additional include files add "yourpath\Pre-built.2\include\"
  • 额外的 lib 文件添加“yourpath\Pre-built.2\lib\x64\”
  • 额外的dll文件添加“yourpath\Pre-built.2\dll\x64\”
  • 其他包含文件添加“yourpath\Pre-built.2\include\”

Choose the correct files according to your project build (x64 or x86).

根据您的项目构建(x64 或 x86)选择正确的文件。