Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinGW, always linking with pthreads

I've recently been trying to use MinGW for my development purposes, but there have been a few issues.

It seems it always wants to link with pthread for some reason. I tried compiling a simple hello world in C and got an error like

ld.exe: cannot find -lpthread

Obviously it is searching for the pthread library and not finding it. I downloaded the library from MinGW-get, and as expected, the compilation and linking worked.

However, after stripping the executable for a simple hello world in C which only includes stdio.h, the file was still 46k large. The same file compiled and stripped with gcc on Cygwin is like 9k, and MSVC is also similar.

So it was complaining about a library missing. Providing the library fixed the problem and made it work. But a stripped hello world in C is still 46k, while with gcc on cygwin it's 9k.

The natural thing to conclude is that MinGW is using the pthread library for some reason.

But I cannot find a way to disable MinGW wanting to link with pthread anywhere. Ironically everything I found on google is people having trouble getting pthread to work with MinGW.

Is there any way to make MinGW not want to link with pthread?

like image 365
supershirobon Avatar asked Aug 28 '16 17:08

supershirobon


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.

Are pthreads still used?

Yes, the pthreads library is still used for threading.

Does Windows use pthreads?

Windows does not support the pthreads standard natively, therefore the Pthreads4w project seeks to provide a portable and open-source wrapper implementation. It can also be used to port Unix software (which uses pthreads) with little or no modification to the Windows platform.

What is difference between pthread and Lpthread GCC flags?

-pthread Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker ( man gcc ). -lpthread comes in existence while linking there will be no influence while preprocessing.


1 Answers

There are several possibilities when installing MinGW-W64 on windows. I am betting that you installed it for posix threads and not win32. Run the setup again and use the compiler from the newly created directory.

MinGW Setup Screen

like image 69
Señor CMasMas Avatar answered Nov 02 '22 12:11

Señor CMasMas