windows下静态编译pthread

1. Building the library as a statically linkable library
-----------------------------------------------------

General: PTW32_STATIC_LIB must be defined for both the library build and the
application build. The makefiles supplied and used by the following ‘make‘
command lines will define this for you.

MSVC (creates pthreadVCn.lib as a static link lib):

nmake clean VC-static

MinGW32 (creates libpthreadGCn.a as a static link lib):

make clean GC-static

Define PTW32_STATIC_LIB when building your application. Also, your
application must call a two non-portable routines to initialise the
some state on startup and cleanup before exit. One other routine needs
to be called to cleanup after any Win32 threads have called POSIX API
routines. See README.NONPORTABLE or the html reference manual pages for
details on these routines:

BOOL pthread_win32_process_attach_np (void);
BOOL pthread_win32_process_detach_np (void);
BOOL pthread_win32_thread_attach_np (void); // Currently a no-op
BOOL pthread_win32_thread_detach_np (void);

The tests makefiles have the same targets but only check that the
static library is statically linkable. They don‘t run the full
testsuite. To run the full testsuite, build the dlls and run the
dll test targets.

=============================================

2. 使用pthread-win32静态库
使用pthread-win32静态库要注意:
1) 在程序中要定义宏PTW32_STATIC_LIB
2) pthread-win32静态库中没有做attach和detach操作,要程序员来完成该任务,
否则线程有能成功创建。具体如下:
在程序入口(通常是main函数)处调用如下两个函数
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
程序结束时调用
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();

没办法,windows系统有很多标准它都不支持,写起来就要麻烦点。
可以简单地这样处理:

a) 定义程序结束时的处理函数
#ifdef PTW32_STATIC_LIB
void pthread_win32_detach(void)
{
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
}
#endif

b) 在程序入口处调用如下
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(pthread_win32_detach);
#endif

时间: 2024-08-07 18:15:48

windows下静态编译pthread的相关文章

图文介绍windows下实现编译ffmpeg工程的详细步骤

本文来自:http://www.cuplayer.com/player/PlayerCode/FFmpeg/2014/0706/1401.html 图文介绍windows下实现编译ffmpeg工程的详细步骤: 1.搭建 MinGW 的编译环境 下载yasm,地址:http://yasm.tortall.net/Download.html 改名为yasm.exe放到C:\WINDOWS\system32 或者 C:\MinGW\msys\1.0\bin文件夹下. 下载 mingw-get-inst

windows下rabbitmq-c编译(带openssl、无需MinGW)

因为项目原因,需要使用到rabbitmq的c客户端库.首先,参见上一篇windows下openssl编译,如果已经使用cmake编译过了,则先delete cache(File-Delete Cache),否则原来的cmake缓存都在了,将仍然会出现原来的错误. 依次点击configire.generate,可以生成vs sln.如下: 最后使用VS即可生成rabbitmq.4.dll,如下: 测试自带的例子: D:\RabbitMQ Server\rabbitmq_server-3.6.5\s

Windows下VC编译OpenDDS

OpenDDS是一个OMG组织DDS标准的C++开源实现,OpenDDS同时也提供Java支持.OpenDDS依赖ACE抽象层来提供不同平台的兼容性,同时也依赖于TAO(例如TAO的IDL编译器).当前OpenDDS有ociweb ObjectComputing维护,官方网站http://www.opendds.org/.目前OpenDDS支持的平台有Windows,Linux family,Android,VxWorks等,可用的编译器包括VC,gcc,QNX gcc等. 1. OpenDDS

【FFmpeg】Windows下FFmpeg编译

转自:http://www.cnblogs.com/dwdxdy/p/3625766.html 由于FFmpeg是基于Linux开发的开源项目,源代码和Windows下最常见的Visual Studio提供的C/C++编译器不兼容,因此它不能使用MSVC++编译,需要在Windows下配置一个类似Linux的编译环境.本文主要记录Windows下FFmpeg编译的过程. 1.资源准备 准备编译过程所需的软件工具和源代码. (1). MinGW-MSYS Bundle http://sourcef

ACE在windows下的编译及配置(VS2010)

ACE在windows下的编译及配置(VS2010) 分类:             -[小西南]-              2013-08-06 16:17     2354人阅读     评论(6)     收藏     举报 目录(?)[+] 1 下载ACE 2 创建ACE的配置文件 3 编译ACE库 4 可为ACE目录设置环境变量 5 VS2010 ACE配置 6 测试操作是否成功 系统:win7 开发环境:Visual Studio 10 ACE版本:ACE-6.2.0 参考了很多师

xcode 5.1 下静态编译 libogg +speex

xcode 5.1 下静态编译 libogg +speex 编译是在命令行模式下进行的.打开终端,首先进入ogg所在的文件夹,我们先编译ogg. 1.ogg-i386的库 ./configure-prefix=/Users/(用户名)/Desktop/libogg-1.3.0/i386 -host=i386-apple-darwin -build=x86_64-apple-darwin11.3.0CXX="/Applications/Xcode.app/Contents/Developer/To

Windows 上静态编译 Libevent 2.0.10 并实现一个简单 HTTP 服务器

Windows 上静态编译 Libevent 2.0.10 并实现一个简单 HTTP 服务器  大 | 中 | 小  [ 2011-3-30 08:40 | by 张宴 ] [文章作者:张宴 本文版本:v1.0 最后修改:2011.03.30 转载请注明原文链接:http://blog.zyan.cc/libevent_windows/] 本文介绍了如何在 Windows 操作系统中,利用微软 Visual Studio 2005 编译生成 Libevent 2.0.10 静态链接库,并利用 L

Windows下PythonQt编译(vs2015+Qt5.11.2+PythonQt 3.2)

时间:2018年10月22日,学习任何物事都有个探索过程.欢迎留言探讨. 在Qt程序中,添加python进行混合编程,可以使用Python API,但交互起来很麻烦,不友好.网上推荐使用PythonQt框架. 强调下: PythonQt,方便Qt C++程序员,将python引入项目 PyQt PySide,给python程序员,将Qt界面引入项目 本机环境: 1.win7 64 旗舰版 2.Qt 5.11.2(MSVC 2015,32 bit) 3.Python 3.7.0 (32-bit)

Mac平台下的Qt程序在Windows下执行编译运行出现的中文乱码问题

Mac平台下的Qt程序在Windows下执行编译运行时,QString::asprintf()部分会出现的中文乱码问题,之前已经使用QStringLiteral宏解决了一个中文乱码问题: 但是此种情形单凭QStringLiteral宏解决不了. 原因: mac下采用MinGW编译,在Windows下可能是MinGW,也可能是MSV2017等VS编译器编译.如果win平台下是MinGW编译,在mac下写好的程序在win平台下运行不会出现乱码: 如果win下是MSV2017编译就会出现中文乱码,需要