如何静态链接pthreads-win32
来源:互联网 发布:域名交易中心 编辑:程序博客网 时间:2024/05/01 16:17
首先要编译静态库: 从ftp://sources.redhat.com/pub/pthreads-win32/下载最新的库安装包,笔者下载的是pthreads-w32-2-8-0-release.exe,自解压到一个目录,用vc7打开pthreads.2目录下的pthread.dsw,会提示工程版本转换,选择全是,然后打开该工程的属性页,在“常规”选项页的配置类型选择“静态库(.lib)”,在“c/c++”选项页的预处理器定义删除_USRDLL和PTW32_BUILD,添加PTW32_STATIC_LIB,确定保存即可。当然,你需要根据你的需要选择运行时库的类型。最后重新生成pthread便可生成我们需要的pthread.lib。
下面讲述如何使用前面生成的静态库:新建一个控制台工程,将pthread.lib拷贝到工程目录,在预处理器定义中添加PTW32_STATIC_LIB,附加包含目录添加pthreads-win32代码所在目录,笔者是E:/pthreads/pthreads.2,附加依赖项添加Ws2_32.lib和pthread.lib即可,简单使用代码如下:
#include <iostream>
#include "pthread.h"
void * Function_t(void * Param)
{
std::cout << "我是线程!" << std::endl;
pthread_t myid = pthread_self();
printf( "线程ID = %d", myid );
return NULL;
}
int main()
{
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
#endif
pthread_t pid;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&pid, &attr, Function_t, NULL);
std::cout << "========================================" << std::endl;
getchar();
pthread_attr_destroy(&attr);
#ifdef PTW32_STATIC_LIB
pthread_win32_process_detach_np();
#endif
return 1;
}
其中
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
#endif
#ifdef PTW32_STATIC_LIB
pthread_win32_process_detach_np();
#endif
对于静态链接方式非常重要,如果没有这段代码,线程将创建失败。
附上代码:http://dl2.csdn.net/down4/20070725/25181217441.rar
- 如何静态链接pthreads-win32
- 如何静态链接pthreads-win32
- 编译并链接pthreads-win32静态库
- Pthreads-win32
- pthreads 链接
- 静态链接pthread-win32
- pthreads for Win32
- 【多线程】pthreads-win32静态库动态库编译方法以及demo示例
- 针对codeblocks:如何使用winmm.lib等等win32编程需要的静态链接库???
- VC++:创建,调用Win32静态链接库
- Win32日记之 动态库 静态库 静态链接
- Pthreads-Win32的使用和一些问题
- 如何制作及链接静态链接库。
- 如何制作及链接静态链接库
- [C++] 如何静态链接imagemagick
- VC win32 static library静态链接库简单示例
- Pthreads
- pthreads
- 中文参考手册--8.MySQL教程--8.3常用查询的例子
- 中文参考手册--8.MySQL教程--8.2输入查询
- 中文参考手册--8.MySQL教程--8.1连接与断开服务者
- JAVA的框架的形成是否会向C#一样,用鼠标编程?
- 中文参考手册---7MySQL语言参考
- 如何静态链接pthreads-win32
- 中文参考手册---6MySQL存取权限系统
- 很全面的,很好的一片论文,主要是在线考试
- 建立自己的WAP手机网站
- 中文参考手册5MySQL与标准的兼容性?
- flex 动态给控件赋值,通过反射遍历MXML中的组件
- 我的愿望---写在三十岁之前
- 中文参考手册3(MySQL许可证和技术支持)
- 读书笔记《道法自然--面向对象实践指南》第二章