14
$ 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?

Tejas Belvalkar
  • 193
  • 1
  • 2
  • 11
  • http://stackoverflow.com/questions/26232432/since-gcc-on-mac-doesnt-support-openmp-what-can-i-do-to-let-it-support – user3710044 Mar 15 '15 at 11:05
  • I believe that Apple has removed gcc and that what appears to be gcc is a a link back to clang. So you have a few options 1) install gcc yourself 2) install the experimental clang with OpenMP support. Google should be your friend in either case. – Jim Cownie Mar 16 '15 at 09:38
  • As fas as installing gcc was concern it did no good.. It showed the same error `` not found where as a simple `Hello World!!!` did execute. Will try clang now, bit reluctant though because of its large size.. – Tejas Belvalkar Mar 16 '15 at 14:34
  • and nope same error.. ` not found` – Tejas Belvalkar Mar 17 '15 at 16:53
  • Possible duplicate of [ library isn't found in the GCC version (4.2.1) in Mavericks](http://stackoverflow.com/questions/20340117/omp-h-library-isnt-found-in-the-gcc-version-4-2-1-in-mavericks) – Mr Tsjolder from codidact Apr 21 '16 at 14:15

2 Answers2

45

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.

IKavanagh
  • 6,089
  • 11
  • 42
  • 47
  • I think Kavanai4 meant, `brew install gcc --without-multilib` –  Jul 08 '15 at 20:28
  • 4
    What does the `--without-multilib` flag mean? – Cullub Jan 14 '16 at 16:51
  • 6
    @cullub It's used to build `gcc` without support for both 32 and 64 bit systems. It is a requirement with Homebrew to add OpenMP support. – IKavanagh Jan 17 '16 at 08:40
  • 3
    I'm pretty sure the `--without-multilib` flag is no longer required. I used OpenMP in January of this year and do not remember using this flag. Can anyone verify this? – Jason Jul 05 '17 at 14:27
  • 2
    @Jason I was getting errors compiling C++ code with OpenMP until I `brew upgrade`'d my gcc to gcc-7.1. Everything works fine now with `g++-7 hello.cpp -fopenmp`, and I didn't have use the `--without-multilib` flag. – Beepboop bebop Jul 06 '17 at 16:23
  • 1
    Running `brew reinstall gcc --without-multilib` now gives `Warning: gcc: this formula has no --without-multilib option so it will be ignored!` – Omar Haque Jun 09 '18 at 13:35
2

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!
Tejas Belvalkar
  • 193
  • 1
  • 2
  • 11
  • 1
    You only need to do step 3, as you have already installed GCC from Homebrew. However, the default installation has a bug. Kavanai4's answer is correct. – Yongwei Wu May 25 '15 at 11:40