vs2010下配置pthread环境详解

转自:https://blog.****.net/hsd2012/article/details/50930236

1.下载pthread 的windows安装包

可以从官方网站上下载,网址:http://sourceware.org/pthreads-win32

也可以下载我上传的资源,以下将以我上传的资源来讲解。(下载

下载之后解压,放置在C盘

如下图:

vs2010下配置pthread环境详解

2.配置VS2010

打开vs2010,项目->属性->配置属性->VC++目录,包含目录里添加inlude路径;在库目录那一栏添加lib路径

vs2010下配置pthread环境详解

添加库目录的时候,根据自己的系统选择;32为选择x86;64位选择x64

vs2010下配置pthread环境详解


在链接器—>输入,附加依赖项一栏添加 pthreadVC2.lib;pthreadVCE2.lib;pthreadVSE2.lib;如下图所示。所有设置完成后点确定

 

vs2010下配置pthread环境详解

 

这样就设置好了,大功告成。可以创建项目测试

 

 
  1. #include "stdafx.h"

  2. #include <iostream>

  3. #include <pthread.h>

  4. using namespace std;

  5.  
  6. void *task1(void *X){

  7. cout<<"线程A complete"<<endl;

  8. return (NULL);

  9. }

  10. void *task2(void *X){

  11. cout<<"线程B complete"<<endl;

  12. return (NULL);

  13. }

  14.  
  15. int main(int argc, _TCHAR* argv[])

  16. {

  17. pthread_t ThreadA,ThreadB; //定义线程

  18. pthread_create(&ThreadA,NULL,task1,NULL);

  19. pthread_create(&ThreadB,NULL,task2,NULL);

  20. pthread_join(ThreadA,NULL);

  21. pthread_join(ThreadB,NULL);

  22. system("pause");

  23. return 0;

  24. }

效果如下图:

vs2010下配置pthread环境详解

--------------------- 作者:我爱默小兜 来源:**** 原文:https://blog.****.net/hsd2012/article/details/50930236?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!