在Win7中使用MinGW中的pthreads

lin*_*bin 4 mingw pthreads

2015-1-20,我在Win7中使用MinGW,尝试使用MinGW和Pthreads编译我的源代码.MinGW已经支持POSIX线程,在"MinGW Installation Manager"中,我们可以安装pthreads dev包和pthreads lib.但是当我编译我的源代码时,有一个错误:struct timespec重新定义,首先在pthread.h中,然后在unistd.h中,我不知道为什么.

在此之前,我实际上安装了没有pthreads dev和lib包的minGW,我下载了pthreads-for-win32源代码并在本地构建它.我使用-I/somewhere -L/somewhere -lpthreadGC2链接到我的源代码,它工作正常.

但这一次,MinGW自包装失败了.我需要帮助.我无法上传图片来向您显示详细信息....

lin*_*bin 6

实际上,我找到了解决方案.

不要在"pthread.h"之后包含"unistd.h",而是使用本地winapi.

在Linux中用gcc编写"pthreads"很容易,但在Win7中不支持,使用"MinGW Installation Manager"(google"mingw"和下载)进行安装.安装mingw时,在"MinGW标准库"中选择"mingw32-pthreads-win32"开发包,然后您不需要下载pthreads-for-win32源代码或在本地构建它.但是"pthread.h"会与"unistd.h"冲突,在Windows中,我们应该使用Windows API而不是unix API.