0

omp.cpp

#include <iostream> #include <omp.h> int main() { std::cout << "Start" << std::endl; #pragma omp parallel { std::cout << "Hello "; std::cout << "World! " << std::endl; } std::cout << "End" << std::endl; } 

I've tried to compile the above code with g++ omp.cpp -fopenmp but I get the error:

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread collect2.exe: error: ld returned 1 exit status 

I've tried googling what -lpthread is but I couldn't find anything. The closest thing I found was another thread in which someone compiled his/her code like this: g++ omp.cpp -fopenmp -lpthread ... but the result is the same for me.

Am I missing something? Much appreciated in advance.

2

1 Answer 1

4

pthread is the POSIX thread library.
-lpthread is a linker argument, meaning you are trying to link your binary with pthread.

The error means that this library is not available on your OS.

It looks like you are using mingw on Windows.
No surprise pthread isn't available on Windows, as it's a POSIX library.

But you may find some ways to have it on the MinGW website: http://www.mingw.org/wiki/pthreads_library

Looks like you'll have to install a third-party library called pthreads-win32:
https://sourceware.org/pthreads-win32/

Sign up to request clarification or add additional context in comments.

3 Comments

Much appreciated. So I've downloaded 'pthreads-w32-1-10-0-release.tar.gz', but I don't know where to put it. Do I put this folder into my MinGW folder? Perhaps this is too much to ask, but I'm really a newbie in this area.
You should have a 'lib' or 'usr/lib' directory in mingw, with other libraries. Try to put pthread here, as this dir is likely to be in the linker search paths.
Unfortunately this didn't work. I've tried a couple of things now, but none of them work. Just why is this stuff so complicated. Anyway, I don't want to spam the comment section now. I appreciate your effort nonetheless.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.