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?
The MinGW has already support POSIX threads, In the "MinGW Installation Manager", we can install the pthreads dev package and pthreads lib.
Yes, the pthreads library is still used for threading.
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.
-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.
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.
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