# pthread_2015 **Repository Path**: chixinfushui/pthread_ ## Basic Information - **Project Name**: pthread_2015 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-01 - **Last Updated**: 2021-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pthread_2015 #### 介绍 {**以下是 Gitee 平台说明,您可以替换此简介** Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) https://www.pianshen.com/article/6327841200/ https://blog.csdn.net/k459905889/article/details/48676159 下载pthreads-w32-2-9-1-release包 百度网盘链接:https://pan.baidu.com/s/1Z7QSK1hVT35Xq9YwpF8khQ 提取码:katg 来自官方地址:https://sourceware.org/pthreads-win32/ 解压下载包 这里只需使用Pre-built.2文件,打开得在这里插入图片描述 只需使用dll,include,lib三个文件. 复制include下的文件,粘贴至vs2015安装目录(这里要依据自己的软件安装路径来找)H:\vs2015\VC\include下; 复制Pre-built.2—> lib文件夹下的x86,x64文件夹,粘贴至vs2015安装目录H:\vs2015\VC\lib下; 复制Pre-built.2–>x64下的两个文件,粘贴至C:\Windows\System32下; 复制Pre-built.2—>x86下的五个文件,粘贴至C:\Windows\SysWOW64下。 链接配置 到这里我们就完成大半了,下面是在软件内的链接配置 项目—>属性–>库目录,根据编译器本身环境(这里debug选的x86)添加上一步粘贴在vs2015安装目录lib文件夹下的x86文件,在这里插入图片描述 进一步,项目–>属性–>配置属性–>C/C+±>预处理器->添加“HAVE_STRUCT_TIMESPEC” ,或者在pthread.h文件的开头,以避免“C2011: “timespec”:“struct”类型重定义”的出现 在这里插入图片描述 在这里插入图片描述 6、 最后,在应用“pthread.h”的代码内添加 #pragma comment(lib,“pthreadVC2.lib”),以避免 LNK2019 无法解析的外部符号 __imp__pthread_exit,该符号在函数 _main 中被引用 Project1 D:\project\vc2015\20200125template\Project1\Project1\main.obj 1 LNK2019 无法解析的外部符号 __imp__pthread_create,该符号在函数 _main 中被引用 Project1 D:\project\vc2015\20200125template\Project1\Project1\main.obj 1 的出现 在这里插入图片描述 以上完毕,如有疑问,欢迎指正交流,。 一、安装平台 Win7\8\10 64位 Microsoft Visual Studio 2015 二、下载 pthreads-w32-2-9-1 tp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip 解压后共有三个文件夹 Pre-built.2 pthreads.2 QueueUserAPCEx 打开Pre-built.2 dll ——>动态链接库 include ——>头文件 lib ——>静态链接库 三、配置头文件及静态链接库 把include文件夹中的三个文件直接拷贝到Visual Studio安装目录下VC->include文件夹下,例如我将include中文件拷贝到的位置是 E:\Software\Microsoft Visual Studio 11.0\VC\include 把lib文件夹下的内容拷贝到Visual Studio安装目录下默认的lib寻找路径中,即VC->lib中,例如我将lib文件夹下的x64与x86两个文件直接拷贝到 E:\Software\Microsoft Visual Studio 11.0\VC\lib 四、配置动态链接库 把dll下的x64文件夹下的两个文件,即pthreadGC2.dll与pthreadVC2.dll拷贝到C:\Windows\System32下(用于64位程序的运行) 把dll下的x86文件夹下的五个文件,拷贝到C:\Windows\SysWOW64下(用于32位程序的运行) 五、运行测试 #include #include #define NUM_THREADS 5 #pragma comment(lib,"pthreadVC2.lib") //必不可少,这是告诉编译器在编译形成的.obj文件和.exe文件中加一条信息,使得链接器在链接库的时候要去找pthreadVC2.lib这个库,不要先去找别的库。(.exe文件找DLL 也是这种写法,例如 pthreadVC2.dll) void *PrintHello(void *threadid) { int tid; tid = (int)threadid; printf("Hello World!It's me,thread #%d!\n", tid); pthread_exit(NULL); } int main(int argc,char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for (t = 0; t < NUM_THREADS; t++) { printf("In main:creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); if (rc) { printf("ERROR:return code from pthread_create() is %d\n", rc); exit(-1); } } pthread_exit(NULL); } ———————————————— 版权声明:本文为CSDN博主「k459905889」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/k459905889/article/details/48676159 {\rtf1}