Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile OpenMP programs with gcc compiler on OS X Yosemite

Tags:

c++

c

xcode

gcc

openmp

$ gcc 12.c -fopenmp
12.c:9:9: fatal error: 'omp.h' file not found
#include<omp.h>
    ^
1 error generated.

While compiling openMP programs I get the above error. I am using OS X Yosemite. I first tried by installing native gcc compiler by typing gcc in terminal and later downloaded Xcode too still I got the same error. Then I downloaded gcc through:

$ brew install gcc

Still I'm getting the same error. I did try changing the compiler path too still it shows:

$ which gcc
/usr/bin/gcc

So how do I compile programs with gcc?

like image 338
Tejas Belvalkar Avatar asked Mar 15 '15 05:03

Tejas Belvalkar


People also ask

Does GCC support OpenMP?

OpenMP 5.0 is partially supported for C and C++ since GCC 9 and extended in GCC 10.

Can you run GCC on Mac?

This is a guide for installing GCC 5.1 on a Mac using MacPorts. It will likely work for later versions of GCC as well. Just substitute "gccx" for "gcc5", where "x" is the desired version. Download and install Xcode from the Mac App Store.


2 Answers

EDIT: As of 13 Aug 2017 the --without-multilib option is no longer present in Homebrew and should not be used. The standard installation

brew install gcc

will provide a gcc installation that can be used to compile OpenMP programs. As below it will be installed into /usr/local/bin as gcc-<version>. The current gcc version available from Homebrew (as of writing) will install as gcc-8. You can compile programs with OpenMP support using it via

gcc-8 -fopenmp hello.c

Alternatively you could put an alias in your .bashrcfile as

alias gcc='gcc-8'

and then compile using

gcc -fopenmp hello.c

Note: I'm leaving the original post here in case it is useful to somebody.

The standard gcc available on OS X through XCode and Clang doesn't support OpenMP. To install the Homebrew version of gcc with OpenMP support you need to install it with

brew install gcc --without-multilib

or as pointed out by @Mark Setchell

brew reinstall gcc --without-multilib

This will install it to the /usr/local/bin directory. Homebrew will install it as gcc-<version> so as not to clobber the gcc bundled with XCode.

like image 154
IKavanagh Avatar answered Oct 01 '22 04:10

IKavanagh


I finally did some research and I finally came across a solution here: <omp.h> library isn't found in the GCC version (4.2.1) in Mavericks.

  1. I got a new gcc complier from http://hpc.sourceforge.net/
  2. Then I placed a new executable folder by $ sudo tar -xvf gcc-4.9-bin.tar -C /
  3. Later I switched to it by export PATH=/usr/local/bin:$PATH that seemed to do the trick!
like image 42
Tejas Belvalkar Avatar answered Oct 01 '22 02:10

Tejas Belvalkar