2

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).

IceFire
  • 4,016
  • 2
  • 31
  • 51
  • 1
    Use TBB instead of OpenMP. –  Nov 02 '17 at 18:14
  • 1
    @manni66 Everything speaks for it, I agree... quite some refactoring effort for my software that I'd like to port, though – IceFire Nov 02 '17 at 18:18
  • The answer to your questions is **yes** and **yes**. Your findings show the problem: *not the **standard** - cannot be changed **easily** - not **easy** to change*. Now for SO, a tutorial request is off topic, but you do not describe specific issues you seem to have run into. – Zulan Nov 02 '17 at 22:35
  • @Zulan I am not searching for a tutorial, otherwise this question was closed. If all my presumptions are correct and I do not oversee anything, then this is the answer to the question that I can live with. I am not yet exhaustively certain, though – IceFire Nov 03 '17 at 07:44
  • why don't you build `Boost` yourself by gcc? I expect it's not a big task. Not sure how it plays with "standard MacOS-clang compiler delivered with MacOS which is ALSO the only compiler XCode9 supports", can you use gcc? otherwise I don't understand why you mentioned it at all – Andriy Tylychko Nov 03 '17 at 12:07

2 Answers2

2

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>

Alexey Bataev
  • 428
  • 3
  • 11
  • You say, I can use the frontend option in some terminal call that you post... Will this activate OpenMP for good or what exactly does this accomplish? I need the OpenMP option within an IDE – IceFire Nov 13 '17 at 15:24
  • This is what actually `-fopenmp` driver option does. It sends option `-fopenmp` to frontend + adds some additional linking options like automatic linking of `libomp`. You can't use driver option directly. Instead, you can try to use the frontend option. Plus you need to add some special options for correct linking manually, i.e. you're doing the same work the driver does. – Alexey Bataev Nov 13 '17 at 16:20
  • From (I think) El Capitan onwards, DYLD_ prefixed environment variables are not passed to shell scripts. I don't have a solution! – Jack Wasey Mar 14 '18 at 11:55
1

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.

Henry Schreiner
  • 905
  • 1
  • 7
  • 18