Mac OpenMP-capable compiler?

I am trying to test a package with a wrapped library in c++ that uses OpenMP. Is there a suitable compiler on the Mac that would be reliably present?


Is it really generally available on the Mac?
Mine came with g++ (apparently not THE g++, but some Mac bastard).
It could not compile w/ OpenMP.

I solved it for myself with brew compiler and libomp, but I can’t really rely on that
on other people’s machines, can I?

A recent macOS will have g++ aliased to clang.

What does g++ --version say?

% g++ --version
Apple clang version 15.0.0 (clang-1500.
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I was successful compiling the lib with:
% clang++ --version
Homebrew clang version 18.1.5
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

If you’re asking whether the default compiler toolchain XCode comes with OpenMP support, then the answer is “no”. Apple doesn’t seem to believe in OpenMP. If you’re asking whether there exist compilers for macOS supporting OpenMP, then the answer is “any other compiler than the default one will likely work”. As you found out, most people tend to install vanilla clang with openmp with homebrew. I believe just installing the llvm openmp package with homebrew, without the full compiler toolchain, should be sufficient for building openmp code with apple clang, but you may need to somehow inform the compiler where to find the openmp runtime.

I understand.

How does one handle testing though? Is there anything one can rely on one testing packages? (Obviously, on the mac.)

What’s wrong with using homebrew to install vanilla clang on a mac?
This also works for CI.

Nothing. I just have no experience with this. So, is there a template for installing compilers on the Mac during a “build” of a package?

Just a note about my use case: I want to test package A, which depends on package B, which wraps a C++ lib.

If these are Julia packages, I’d use BinaryBuilder.
You can try running the wizard. It will download the needed compilers, but anyone actually using the Julia package once you have it on yggdrasil will just download the jll without the need to build it at all – much faster, and much more reliable.
It should have reasonable compilers available.