Win10+VS2017配置pthread

摘要:
0.下载pthread源代码:https://sourceware.org/pthreads-win32/1下载pthreads-w32-2-9-1版本后。zip,解压缩。内容如下:[Pre-build.2]是pthreadsforwin32的头文件和库文件,[pthreads.2]是源代码,[QueueUserAPCEx]是驱动程序,需要由WDK编译。2.更改[.pthread

0、pthread源码下载:https://sourceware.org/pthreads-win32/

1、下载pthreads-w32-2-9-1-release.zip完毕后,解压,内容如下

Win10+VS2017配置pthread第1张

其中,【Pre-built.2】是pthreads for win32的头文件和库文件,【pthreads.2】是源代码,【QueueUserAPCEx】是一个驱动,需要WDK支持编译。

2、将【.pthreads-w32-2-9-1-releasePre-built.2include】目录下的头文件拷贝到VS2017的安装目录,当前环境下是【C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.16.27023includeWin10+VS2017配置pthread第2张

3、把【.pthreads-w32-2-9-1-releasePre-built.2lib】下的静态库文件拷贝到VS2017的安装目录,当前环境下是【C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.16.27023lib】,x86和x64对Win10+VS2017配置pthread第3张

4、把【.pthreads-w32-2-9-1-releasePre-built.2dll】下的动态库文件拷贝到系统目录下,x86文件对应C:WindowsSysWOW64目录,x64文件对应C:WindowsSystem32目录

Win10+VS2017配置pthread第4张

也可以在某个项目中引用该库,或者用更加时髦的Nuget也可以找到这个库。

配置好后,可用以下代码进行测试:

1 #include "pch.h"2 #include <iostream>3 #include <stdio.h>4 #include <pthread.h>5 #include <assert.h>6 7 #pragma comment(lib,"x86/pthreadVC2.lib")8 9 void* Function_t(void*Param)10 {11     std::cout << "多线程 " <<std::endl;12     pthread_t myid =pthread_self();13     std::cout << "线程ID=" << myid.x <<std::endl;14     returnNULL;15 }16 17 intmain(int argc, const char *argv[])18 {19 pthread_t pid;20 pthread_attr_t attr;21     pthread_attr_init(&attr);22     pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);23     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);24     pthread_create(&pid, &attr, Function_t, NULL);25     std::cout << "======================================== " <<std::endl;26 getchar();27     pthread_attr_destroy(&attr);28     return 0;29 }

如果在编译时报错【C2011 “timespec”:“struct”类型重定义】,原因是【pthread.h 中的 timespec 和 time.h 中的结构定义重复了,同时两个头文件中的编译条件不同,造成了结构的重复定义】,

解决方案:

#if !defined( PTHREAD_H )
#define PTHREAD_H
下面加上
#define HAVE_STRUCT_TIMESPEC

免责声明:文章转载自《Win10+VS2017配置pthread》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Java开发小技巧(五):HttpClient工具类Thinkphp6笔记五:路由配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

SSI简介 与 nginx开启SSI

Server Side Include : 服务器端嵌入 原理 : 将内容发送到浏览器之前,可以使用“服务器端包含 (SSI)”指令将文本、图形或应用程序信息包含到网页中。因为包含 SSI 指令的文件要求特殊处理,所以必须为所有 SSI 文件赋予 SSI文件扩展名。默认扩展名是 .stm、.shtm 和 .shtml 主要有以下几种用用途: 1、显示服务器...

jsp语法与标签

语法: <% 多行java代码 %> 在一个JSP页面中可以有多个脚本片断,在两个或多个脚本片断之间可以嵌入文本、HTML标记和其他JSP元素。 举例: <% int x = 10; out.println(x); %> <p>这是JSP页面文本</p> <...

qt 界面去掉系统边框

该代码在Qt5框架编辑,使用该类时, 直接继承这个类就可以了。 实现了拖拽功能和关闭功能,如果需要放大缩小功能, 需自己实现。 1 #ifndef CUSTOMIZE_QWIDGET_H 2 #define CUSTOMIZE_QWIDGET_H 3 #include <QWidget> 4 #include <QMouseE...

【DLL相关】实现函数的DLL封装,并在另一个项目中调用

直接给出步骤: ===========函数的DLL封装=========== 1.创建第一个项目:win32控制台程序,应用程序类型:DLL,附加选项:导出符号(命名:double_dll) 2.double_dll.h中加入函数定义   extern DOUBLE_DLL_API int doublefun(int);//DOUBLE_DLL_API 根...

NX二次开发-获取面的法向向量UF_MODL_ask_face_data

1 NX9+VS2012 2 3 #include <uf.h> 4 #include <uf_modl.h> 5 #include <uf_obj.h> 6 #include <uf_ui.h> 7 8 9 UF_initialize()...

Qt5-控件-QRadioButton-单选按钮-用于从多个选项中选取一个-单选神器

#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QRadioButton> #include <QButtonGroup> class MainWindow : public QMainWindow { Q_...