2015-1-20, I use MinGW in my Win7, try to compile my source code with MinGW and Pthreads. The MinGW has already support POSIX threads, In the "MinGW Installation Manager", we can install the pthreads dev package and pthreads lib. But when I compile my source codes, there's an error: struct timespec redefinition, first in pthread.h, then in unistd.h, I don't know why.
Before this, actually I install the minGW without the pthreads dev and lib package, I download the pthreads-for-win32 source code and build it locally. I use -I/somewhere -L/somewhere -lpthreadGC2 to link to my source code, and it worked.
But this time, it fail with MinGW self package. I need help. I cannot upload a picture to show you the details....
The MinGW has already support POSIX threads, In the "MinGW Installation Manager", we can install the pthreads dev package and pthreads lib.
Windows does not support pthreads directly, instead the Pthreads-w32 project seeks to provide a portable and open-source wrapper implementation. This will be the location of where your project dependencies and additional library files will be located.
Here is the procedure. After opening the installation manager go to all packages and select the select packages named using mingw32-pthreads-w32 and select them for installation. Then go to the installation -> Apply changes to install new packages. The you can use pthread.
Actually, I find a solution.
Don't include "unistd.h" after "pthread.h", use local winapi instead.
It's easy to code with "pthreads" with gcc in Linux, but this is not support in Win7, use "MinGW Installation Manager" (google "mingw" and download) to install. Choose the "mingw32-pthreads-win32" dev package in "MinGW Standard Library" when you install the mingw, then you don't need to download pthreads-for-win32 source code or build it locally. But the "pthread.h" will conflict with "unistd.h", in Windows, we should use Windows API instead of unix API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With