Cannot find -lpthread?

26,966

Solution 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.

Solution 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.

Solution 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.

Solution 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.

Share:
26,966
neurothew
Author by

neurothew

Updated on November 25, 2020

Comments

  • neurothew
    neurothew over 3 years

    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.

  • vinod
    vinod about 10 years
    Please check this link also :stackoverflow.com/questions/14770147/…
  • neurothew
    neurothew about 10 years
    I have done exactly the same thing. The only difference is that I did not find any GCC C Linker but I only found MinGW C Linker.
  • neurothew
    neurothew about 10 years
    I have downloaded everything from the website and put the .lib .a files in to C:\MinGW\lib, header files in C:\MinGW\include and the dll files in C:\Windows. But the problem still happened, I don't know if I am missing anything important.
  • alk
    alk about 10 years
    @user1906523: You might like to quote the full output you see on Eclipse's console when building.
  • neurothew
    neurothew about 10 years
    There is just one error - "cannot find -lpthread", nothing else.
  • alk
    alk about 10 years
    @user1906523: The pthread libs under Windows carry a suffix to their name. Check out what the suffix is and adjust Eclipse's library configuration accordingly. If for example the library is called libpthreadGC2.dll change pthread to pthreadGC2 in Eclipse.
  • neurothew
    neurothew about 10 years
    I have tried to change the -pthread to -pthreadVC2. The project can be built but there is no exe coming out. The Console is like this: Info: Internal Builder is used for build gcc -O0 -g3 -Wall -pthreadvc2 -c -fmessage-length=0 -o Testing.o "..\\Testing.c" gcc: error: unrecognized command line option '-pthreadvc2' I have put the library files in the correct location, but it still say that there is unrecognized command line option.
  • alk
    alk about 10 years
    @user1906523: Ok, this is more complicated, as there are two options. 1st to compile sources using PThreads. For gcc that is -pthread and shall not be changed. 2nd there is the option -l<pthread-lib-name> to link the objects resulting from compilation to the pthread-library. For gcc the latter should be -lpthreadGC2 or alike, -lpthreadVC is definitly wrong for gcc as the suffix VC indicates it is for use with the Visual C compiler/linker-suite. Btw: if the suffix is capitialised, apply it capitalised.
  • minghua
    minghua over 7 years
    I believe this is the right answer. But I used the cygwin library. See my answer.
  • qsfzy
    qsfzy over 3 years
    Just a note: this worked for me too, but only after installing the "mingw32-pthreads-w32-dev" package specifically. I think I know why now, but it wasn't totally obvious.