Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apple clang -fopenmp not working

Tags:

clang

openmp

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.

like image 785
grigor Avatar asked Oct 17 '16 21:10

grigor


People also ask

Does Mac Have clang?

From Xcode 4.2, Clang is the default compiler for Mac OS X.

What is the latest Clang version of Mac?

Clang 14, the latest major version of Clang as of March 2022, has full support for all published C++ standards up to C++17, implements most features of C++20, and has initial support for the upcoming C++23 standard. Since v6.


2 Answers

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
like image 83
Yongwei Wu Avatar answered Sep 20 '22 21:09

Yongwei Wu


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.

like image 37
grigor Avatar answered Sep 21 '22 21:09

grigor