问题
I am new to C programming.
I was trying to use the pthread API to write some concurrent program.
I downloaded eclipse IDE for C/C++ Developers, MinGW. I have put all the library, header files into the corresponding location of the MinGW file.
When I tried to build the project, there is always an error "cannot find -lpthread", what happened? I have added the "-pthread" to the GCC compiler.
I have searched a lot in Google but seems no one have similar problem as me.
回答1:
The answer to this question by someone who is also missing MinGW pthread library should help you out! Essentially the issue is that the MinGW installer script might not download the lpthread library upon installation. Quoted from link:
Just run and open MinGW Installation Manager, which should be pre-installed with MinGW, select "All Packages" on the left panel, and on the right panel, search for "mingw32-pthreads-w32" packages and install them.
回答2:
I downloaded eclipse IDE for C/C++ Developers, MinGW.
MingGW uses the Windows API. The Windows API does not provide PThreads.
You need to install PThreads for Win32 to have PThreads available under Windows, and with this available under MinGW.
回答3:
Eclipse is not configured to put the -pthread argument in the gcc compilation. To solve this, go to the Menu: view sourceprint? 1.Project -> Properties
From the bar on the left: view sourceprint? 1.c/c++ build -> GCC C Compiler -> Miscellaneous
Add the “-pthread” argument into the beginning of the “Other Flags” Also go to: view sourceprint? 1.c/c++ build -> Settings -> GCC C Linker -> Libraries
And include the “pthread”library into the other libraries. Click Apply and rebuild the project. Pthreads must work now.
回答4:
See the question on mingw.org. I ended up with adding 'C:/cygwin/lib'
to the settings for the "Library search path (-L)" at properties >> c/c++ build >> settings >> MinGW C Linker >> Libraries
.
来源:https://stackoverflow.com/questions/21827392/cannot-find-lpthread