在windows下vs使用pthread

首先从http://sourceware.org/pthreads-win32/下载pthread 的windows安装包,我下的是pthread-w32-2-9-1-release.zip,其他版本也可以。解压到pthread-w32-2-9-1-release。

该目录会多出三个文件夹:Pre-built.2,pthreads.2,QueueUserAPCEx。这里我们主要使用Pre-built.2,里面包含了编译好的lib和dll。

 

然后添加加库和头文件。

 

方法1:在工程中添加

1.     在Project ->Pthread_TestProperties -> Configuration Properties-> C/C++ -> General ->AdditionalInclude Directories 中增加头文件路径。

2.     在Project ->Pthread_Test Properties -> ConfigurationProperties-> Linker -> General-> Additional Library Directories 中增加库文件路径。我用的是x86库。

3.     在Project ->Pthread_Test Properties -> ConfigurationProperties-> Linker -> Input ->Additional Dependencies中增加所依赖的库文件。这里我们使用的IDE是VS2010,所以我们使用pthreadVSE2.lib。

如果不在这里添加pthreadVSE2.lib 则在程序中要声明:

#pragma comment(lib, "pthreadVC2.lib")

 

方法2:将头文件和库添加到vc目录下

其中需要的是Pre-built.2文件夹里面的内容

首先将里面的include文件夹和lib文件夹里面的文件拷到VS安装目录下的include和lib文件夹下

 

最后配置动态链接库

1.     将把dll下的x64文件夹下的两个文件,即pthreadGC2.dll与pthreadVC2.dll拷贝到C:\Windows\System32下(用于64位程序的运行)

2.     把dll下的x86文件夹下的五个文件,拷贝到C:\Windows\SysWOW64下(用于32位程序的运行),注意一下,千万不能将这些文件拷贝反位置,否则,程序运行时会提示说找不到对应的dll文件

 

 




posted @ 2017-04-07 14:38  蓝天飞翔的白云  阅读(3359)  评论(0编辑  收藏  举报