使用pthread-win32工程编译静态库


1、准备工作

pthread-win32的下载地址: https://sourceware.org/pthreads-win32/#download


2、编译pthread-win32静态库

(1)、解压下载后的压缩件,解压后,有“Pre-built.2”、“pthreads.2”两个文件夹,源码就在pthreads.2文件夹下。

(2)、用vs2010打开pthreads.2下面的工程“pthread.dsw”

(3)、vs工程打开后,打开项目的属性页-》配置属性-》常规-》配置类型-》静态库(.lib)

(4)、vs工程打开后,打开项目的属性也-》配置属性-》C/C++-》预处理器-》预处理定义添加:PTW32_STATIC_LIB

(5)、在使用phread-win32静态库的项目中,项目属性-》配置属性-》C/C++-》预处理器-》预处理定义也要添加:PTW32_STATIC_LIB


3、测试用例

#include<stdio.h>
#include<pthread.h>
#include<Windows.h>
 
void*Function_t(void* Param)
{
     pthread_t myid = pthread_self();
     while(1)
     {
         printf("线程ID=%d \n", myid);
         Sleep(4000);
     }
     return NULL;
}
 
int main()
{
     pthread_t pid;
     pthread_create(&pid, NULL, Function_t,NULL);
     while (1)
     {
         printf("in fatherprocess!\n");
         Sleep(2000);
     }
     getchar();
     return 1;
}

参考网址:http://blog.csdn.net/fksec/article/details/41517953

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值