您的位置:首页 > 其它

Windows系统下pthread环境配置

2017-11-09 09:30 1241 查看
记录下win7系统,vc6.0++编译器下配置POSIX多线程环境的步骤。

配置

下载地址 ftp://sourceware.org/pub/pthreads-win32/

我下载的版本是 fpthreads-w32-2-1-0-release.exe 2005/3/16

运行后点Exract,解压完成后再点Done,可以看到三个文件夹,但只需要用到Pre-built.2文件夹。

Pre-built.2/include中的三个头文件复制到vc的Include文件夹内

Pre-built.2/lib中的8个文件复制到vc的Bin文件夹内(不知道需不需要,反正移就完事了)

Pre-built.2/lib中的pthreadVC2.libpthreadVSE2.lib复制到vc的Lib文件夹里(否则会出现链接错误
LNK1104:cannot open file "pthreadVC2.lib"


Pre-built.2/lib中的pthreadVC2.dll文件复制到C:\Windows\system里面(我的电脑中有system和system32两个文件夹,试了下发现应该放在system中)

配置完成,编程的时候需要包含pthread.h头文件,并且要加上一句
#pragma comment(lib, "pthreadVC2.lib")
(否则会出现链接错误)

测试

#include <cstdio>
#include <pthread.h>
#pragma comment(lib, "pthreadVC2.lib")

void * fun(void * arg) {
printf("Hello, %s\n", (char *) arg);

return NULL;
}

int main(void) {
pthread_t t1, t2;

pthread_create(&t1, NULL, fun, "thread1");
pthread_create(&t2, NULL, fun, "thread2");
pthread_join(t1, NULL);
pthread_join(t2, NULL);

return 0;
}


输出结果

Hello, thread1
Hello, thread2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: