15

I am trying to use openmp with Apple clang but can't make it work. I did download and compile the openmp library from llvm. My problem is that clang doesn't recognize the -fopenmp flag. I get the following error:

clang: error: unsupported option '-fopenmp'

I have version 8 of Xcode and clang. Any help would be much appreciated.

grigor
  • 1,584
  • 1
  • 13
  • 25
  • Have a look here... http://stackoverflow.com/a/39983933/2836621 – Mark Setchell Oct 17 '16 at 21:42
  • Thanks. I know how to use openmp with gcc. My question is about using openmp specifically with clang. – grigor Oct 17 '16 at 21:46
  • Or this maybe... https://gist.github.com/fyears/59e67cf0f521bc199235 – Mark Setchell Oct 18 '16 at 07:15
  • what version of clang are you using? I don't know what xcode 8 has. I can tell you that clang 3.9 supports it using the prebuilt binaries here: http://llvm.org/releases/download.html so does my system clang: zacs-MacBook-Pro:test_blp xaxxon$ /usr/bin/clang -fopenmp clang: error: no input files zacs-MacBook-Pro:test_blp xaxxon$ ls -l /usr/bin/clang -rwxr-xr-x 1 root wheel 18176 Jul 8 20:03 /usr/bin/clang – xaxxon Oct 20 '16 at 10:17
  • There are many questions about OpenMP and Clang here, just search http://stackoverflow.com/questions/tagged/clang+openmp?sort=votes&pageSize=50 . Older versions of clang don't support OpenMP. Clearly, your version does not support it, it explicitly says so in the message. Find a version which does. – Vladimir F Героям слава Oct 21 '16 at 10:53
  • 1
    FYI, re. several of the answers: homebrew no longer supports `clang-omp` – batpigandme Aug 24 '17 at 14:04

2 Answers2

10

There is a way to use OpenMP with just Apple Clang. I learnt it while hacking a formula in Homebrew. You need libomp from Homebrew (brew install libomp), and then a different command-line option.

If you originally want to use clang -fopenmp test.c, with Apple Clang you need to use this alternative command:

clang -Xpreprocessor -fopenmp test.c -lomp
Yongwei Wu
  • 5,292
  • 37
  • 49
2

From what I learned so far is that clang that comes with xcode does not support openmp. Also, the versions are different. So clang that comes with xcode 8 has version 8...

The best solution I have found so far is to install clang using homebrew: brew install llvm --with-clang. Right now I got version 3.9.0 and it does support openmp, so it solves my problem.

grigor
  • 1,584
  • 1
  • 13
  • 25
  • 8
    Warning from Homebrew for the command you provided: **llvm: this formula has no --with-clang option so it will be ignored!** – glihm Mar 21 '17 at 11:16
  • 2
    @glihm, The homebrew llvm removed the clang option in favor of including it by default. So now if you just do `brew install llvm` you should get the clang and clang++ compilers. However, it looks like lldb has recently been completely removed, so if you want lldb support, you will have to get it from somewhere else. Perhaps the answer should be updated? – Jvinniec Mar 27 '19 at 16:11