I have tried many things now and have come to some conclusions. Maybe, I oversee something but it seems that I cannot accomplish what I desire.
The question is: Is there any possibility to compile C++ on MacOS High Sierra with OpenMP and boost?
Some findings (correct me if I am wrong):
- OpenMP is supported by Clang BUT not by the standard MacOS-clang compiler delivered with MacOS which is ALSO the only compiler XCode9 supports
- g++ supports OpenMP
- If I install Boost via homebrew, then it will use the clang compiler (which cannot be changed easily), so that libc++ will be used
- g++ uses libstdc++ by default which is not easy to change
As a consequence, it seems that I cannot have both... OpenMP is only supported if I use gcc. But gcc uses libstdc++ instead of libc++, so that I get linker errors if I try to link against boost installed via homebrew with libc++.
Is there any chance to get both OpenMP and and boost running?
PS: Please don't link to some >1 year old threads, XCode8 is another story (earlier XCode versions support different compilers) and clang-omp would be another story (it is no longer supported).
Standard Apple's clang supports OpenMP. They just disabled the driver option. But you can use the frontend option instead this way:
clang -Xclang -fopenmp <you_program> -L <path to libomp.a> -lomp
Also, you need to set DYLD_LIBRARY_PATH environmental variable:
export DYLD_LIBRARY_PATH=<path to libomp.dylib>
Since you mentioned in passing brew install clang-omp
, it's been merged into brew install llvm
. That's really a very useful choice if you are willing to do it, since you get llvm 5 and C++17 if you need it. It's fully OpenMP compatible using the standard options (ie, -fopenmp
).
You can also try my brew formula to use the built-in clang, but you'd still need to set up custom options as in Alexey Bataev's answer. Install with brew:
brew install cliutils/apple/libomp
This only adds the openMP dynamic library and header, nothing else. Then build with:
clang++ -Xpreprocessor -fopenmp -lomp <other arguments...>
See the readme. If you are using cmake, the helper file here might help.
来源:https://stackoverflow.com/questions/47081991/is-c-compilable-with-openmp-and-boost-on-macos