I've tried to compile this with the command g++ omp.cpp -fopenmp (or g++ -fopenmp omp.cpp) but I always get the error message: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
What I've tried to do:
I've asked this question on StackOverfow and I've been told that I'm missing pthread. I've downloaded phtread from here: https://sourceware.org/pthreads-win32/
I've added pthread.h, shed.h and semaphore.h to MinGW/include. libpthreadGC2.a and libpthreadGCE2.a are in MinGW/lib. pthreadGC2.dll and pthreadGCE2.dll are in MinGW/bin
I've tried various other locations, but I just can't get openmp running. What do I have to do? I'm using Windows 7 if that matters. I'm a total newbie regarding such matters, so bear with me.
PS: I think I've got it working for Visual Studio, but I'd like to be able to work with Notepad++ and DOS
Thank you for your answer, but what exactly am I supposed to do? I've googled what you typed there and I've ended up downloading a file named pthreads-w32-2.9.1-1-mingw32-dll.tar.lzma but neither am I sure whether this is the right one, nor am I sure what to do with it.
I'd really need a more detailed explanation, because as I said, I'm a fullfledged newbie considering stuff like this. :(
The mingw-get is a package manager. According to net, it has both CLI and GUI modes. I hope it has some kind of manual/help too.
Looking further about it, the more proper CLI command might be "mingw-get install mingw32-pthreads-w32"
The idea of a package manager is that it somehow knows where to put the files (and thus can "uninstall" too), updates only installed packages, can at least tell whether some other packages have to be installed too as dependencies, and usually is able to download necessary packages from a network repository. Package management is miles better than trying to manually guess and remember where files do belong.
An another question is that I merely made guesses about "mingw32" and "mingw-get". You did not state how you have installed your GCC. For what I know, you might have installed it along some IDE (other than MSVS). Such IDE could have its own installer/package manager.
I've installed that one now. It has its own folder in C:\. Do I have to include it in some kind of PATH-variable? Becasue as of now I still can't compile my code with -fopenmp
a. Installation: be sure to install the "openmp" optional package.
(It is not selected in the default install; you have to explicitly select it)
b. To place tdm-gcc in the path, from the command prompt, run the batch file mingwvars.bat in the installation directory.
c. Check that everything is ok by entering the command: g++ --version
You should get:
g++ (tdm64-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
d. You are ready to go; just compile with g++ -std=c++14 -Wall -Wextra -pedantic-errors -fopenmp openmp_test.cpp
I've done (a). I cannot do (b) because I have no mingwvars.bat file [by installation directory I assume you mean the TDM-GCC-64/__install directory?]. However, the installation apparently does add it to PATH? Because it is there. I've added it to the user variables as well.
When running (c) I get:
g++ (GCC) 4.8.1
Copyright (c) 2013 ...
Do I have to update my MinGW or should that have happened with TDM?
> by installation directory I assume you mean the TDM-GCC-64/__install directory?
No. The root of the installation: if you have installed tdm gcc in C:\TDM-GCC-64 look for C:\TDM-GCC-64\mingwvars.bat
It appears that an older installation of GCC (version 4.8.1) is placed ahead in the PATH
(You should get g++ (tdm64-1) 4.9.2 if it is tdm gcc)
If you type PATH from the command line, what does it print oput?
Much much much much appreciated. Thank you so much for your patience. It works now.
So I had to delete MinGW/bin from my path, as it occured before TDM. Another mistake I made was that I didn't "refresh" my command-line. I thought it'd recognize every change made, but it didn't, I think. So after re-opening it (after having changed the PATH) it did work.
One last question. Should I add MinGW\bin to the end of the PATH, or is it unnecessary at this point?