Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find -lpthread?

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.

like image 570
neurothew Avatar asked Feb 17 '14 11:02

neurothew


3 Answers

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.

like image 97
APaul Avatar answered Nov 16 '22 06:11

APaul


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.

like image 42
alk Avatar answered Nov 16 '22 04:11

alk


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.

like image 1
vinod Avatar answered Nov 16 '22 06:11

vinod