I installed Xcode (and also the command line tools) but terminal says (when I'm compiling):
gcc -o task -fopenmp task.c
clang: error: unsupported option '-fopenmp'
I tried to install openmp via brew but people say that it's not available anymore on homebrew, they suggest to try
brew instal llvm
But I get the same error. I tried also in the boneyard
brew install homebrew/boneyard/clang-omp
but the repository doesn't exist anymore.
Could you help me? I just need to learn openMP, I don't think that is so difficult to install...
Thank you!
Kind regards,
Nico
To build with OpenMP support, you need to make sure you're not invoking Apple's clang from Xcode. Even if you install llvm
or gcc
via brew, you should try gcc -v
and clang -v
in your terminal session. Both likely invoke Apple's version.
You can use GNU gcc or LLVM; both are available via brew. If you use LLVM, you'll also need to install libomp
.
brew install gcc
gcc-9 -o task -fopenmp task.c
Note that you invoke this version of gcc explicitly by suffixing gcc
with a -
and the major version number, eg: gcc-9
Brew installs LLVM as keg-only so that it doesn't conflict with Apple's version. You'll therefore need to make sure you invoke the right clang
. You'll also need to specify where the libomp
library is located.
brew install llvm libomp
`brew --prefix llvm`/bin/clang -L`brew --prefix`/lib -o task -fopenmp task.c
This https://iscinumpy.gitlab.io/post/omp-on-high-sierra/ suggest to do the following:
brew install libomp
To install the OpenMP runtime components/libraries.
Then, when compiling:
-Xpreprocessor -fopenmp
in place of -fopenmp
in the compile step ( -c
option)-lomp
to the linking stepNote that the above page also mention that CMake 3.12 or later will automatically find the right way of adding OpenMP on MacOS:
cmake_minimum_required(VERSION 3.12)
project(openmptest CXX)
add_executable(sample sample.cpp)
find_package(OpenMP REQUIRED)
target_link_libraries(sample PRIVATE OpenMP::OpenMP_CXX)
Note: I didn't test any of this but it sounds relatively sane
brew install gcc
then type gcc
in your terminal and hit the tab button twice.
you should see multiple gcc versions eg gcc
gcc-10
then find out which one is from Homebrew eg type gcc-10 --version
in the terminal should output something like this:
gcc-10 (Homebrew GCC 10.2.0_3) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Finally use that compiler to compile your eg:
gcc-10 -o task -fopenmp task.c
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.