I'm new in C and have some problems compiling my code in OS X.
I code Java a lot both in Eclipse and use terminal to compile my code. However now I'm learning openMP and have troubles with it.
First I downloaded Xcode to write openMP code but it didn't recognize <omp.h>
. Then I installed g++
. When I type g++ -v
into terminal I get this:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
But when I use g++ Mesh.cpp -fopenmp
I still get
Mesh.cpp:4:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
Then I tried to install PTP into my Eclipse and got the same problem.
I thought there was no omp.h
in my MacBook so I searched for it and found several omp.h
under folders under gcc-4.9.1/build/
.
Here comes the problem. Based on the Java experience the only reason why I have the file but cannot use it is that the Class Path is wrong. However, I have no idea how to change this configuration in g++, or in Xcode, or in Eclipse. But since I can include files like <stdio.h>
and compile it with all the IDEs, how can't I do the same with <omp.h>
?
Another thing I noticed is that the gcc folder version is 4.9.1
, but when I type gcc -v
into terminal I get the same with typing in g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Shouldn't the version information says something about 4.9.1
? Just like what java -version
shows
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
Thanks for reading. Any help is appreciated.
The
gcc
andg++
commands are not what you think they are with XCode: Apple thought it would be a good idea to masquerade Clang as GCC to make the transition smoother.Clang OpenMP support is still being worked on. If I didn't miss any big release of the WIP code, you'll need to build this version of clang and use that.
You can of course always install a real GCC through stuff like homebrew or macports, that will come with OpenMP support.
This command can help you
GCC 4.9.1 normally does not ship with OS X (actually no GCC ships with Xcode any more). Yours must have been installed by another means, e.g. Homebrew or self compilation as described here. What you are probably missing is properly set
PATH
variable or the additionally installed compiler has version-suffixed binaries, i.e.gcc-4.9
org++-4.9
instead of simplygcc
/g++
.As @rubenvb has already mentioned, Apple symlinks the Clang executables with GCC-like names. I personally find that a bad practice since recent Clang versions shipped with Xcode react on unrecognised command-line options (e.g. GCC frontend specific ones) with hard errors.
The
omp.h
file has been moved to a subdirectory. I found it in MacPorts and solved this compilation problem by creating a link to this file: