Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use pthreads in MinGW in Win7

Tags:

mingw

pthreads

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....

like image 222
linrongbin Avatar asked Jan 20 '15 02:01

linrongbin


People also ask

Does MinGW support pthread?

The MinGW has already support POSIX threads, In the "MinGW Installation Manager", we can install the pthreads dev package and pthreads lib.

Can I use pthreads in Windows?

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.

How do I run pthread on Windows?

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.


1 Answers

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.

like image 173
linrongbin Avatar answered Jan 01 '23 11:01

linrongbin