Why does C++ “Hello World” require pthread (which

2019-07-26 03:25发布

问题:

I've been running Eclipse Juno and MinGW 4.6.2 for a long time, but I need full C++11 support so I upgraded to Eclipse Mars and installed MinGW 4.9.3 in a different directory.

In Mars, linking any executable - even in the C++ Hello World project - results in "C:\MinGW_4_9_4\bin...\ld.exe: cannot find -lpthread."

The 4.6.2 directory (for Juno) contains pthread, but the 4.9.3 directory (for Mars) does not.

Why and How is Mars trying to link to pthread? (Can I turn it off?)

回答1:

I couldn't determine if it's possible to link w/o pthread, but I'd noticed that pthread was not present after I installed (and re-installed w/maxmium options) MinGW 4.9.3. Maybe it's an installer bug?

In 2008, MinGW said "Use sourceware.org's pthreads-win32 at your own risk". I now see mingw-pthreads-win32 is a standard library in the MinGW Installation Manager Setup Tool (mingw-get.exe). I feel save with MinGW's purist attitude regarding Win-32, so I installed the library. Hooray - problem solved! ld.exe can now find -lpthread.

You can find the package in the MinGW Installation Manager Setup Tool, under "All Packages/MinGW/MinGW Libraries/MinGW Standard Libraries" in the left pane; it's the "mingw-pthreads-win32" package ("dev" class) in the right pane.