How to include omp.h in OS X?

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 or g++-4.9 instead of simply gcc / 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.


This command can help you

brew install libomp

brew info libomp
libomp: stable 6.0.1 (bottled)
LLVM's OpenMP runtime library
https://openmp.llvm.org/
/usr/local/Cellar/libomp/6.0.1 (12 files, 1.2MB) *
  Poured from bottle on 2018-11-20 at 16:12:22
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libomp.rb
==> Dependencies
Build: cmake ✘
==> Requirements
Required: macOS >= 10.10 ✔
==> Caveats
On Apple Clang, you need to add several options to use OpenMP's front end
instead of the standard driver option. This usually looks like
  -Xpreprocessor -fopenmp -lomp

You might need to make sure the lib and include directories are discoverable
if /usr/local is not searched:

  -L/usr/local/opt/libomp/lib -I/usr/local/opt/libomp/include

For CMake, the following flags will cause the OpenMP::OpenMP_CXX target to
be set up correctly:
  -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib

The gcc and g++ 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.


MacOS seems to have that library included but XCode can't find it if you simply use:

#include <omp.h>

However, if you don't have the library installed,you can simply add it by installing it with HomeBrew:

brew install libomp

After doing this , simply replace library include code with this one:

#include "/usr/local/opt/libomp/include/omp.h"

or the path that terminal shows you after installing libomp with brew.

Tags:

C++

Gcc

G++

Openmp