macoscmakecompiler-errors

cmake compilation error macOS: Could NOT find OpenMP_C


I have been having trouble with compiling several totally unrelated programs using cmake on my MacBook Pro M1 Max, but I keep getting the same error. After typing in cmake -B build (plus the program's respective options), a small number of processes begin, but eventually I get an error saying:

CMake Error at /opt/local/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
  /opt/local/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /opt/local/share/cmake-3.29/Modules/FindOpenMP.cmake:581 (find_package_handle_standard_args)
  build/_deps/mctc-lib-src/CMakeLists.txt:50 (find_package)


-- Configuring incomplete, errors occurred!

I have been having this problem for weeks now, with at least three different programs. I found multiple posts where people have similar (possibly identical) problems (this post in particular sounds very similar), but I have not yet found a solution that has worked.

From everything I have read, it sounds like cmake is trying to use Xcode's version of Clang, but this doesn't support MPI, and I need to direct cmake to the system's (or, in my case, MacPort's) installation of Clang.

So far, I have tried to do this by setting the environment variables prior to the cmake command:

export CC=/opt/local/libexec/llvm-19/bin/clang
export CXX=/opt/local/libexec/llvm-19/bin/clang++
export LDFLAGS="-L/opt/local/libexec/llvm-19/lib" 
export CPPFLAGS="-I/opt/local/libexec/llvm-19/include"

I have also tried to include it in the cmake command itself:

cmake -B build -DCMAKE_BUILD_TYPE=Release -DCC=/opt/local/libexec/llvm-19/bin/clang -DCXX=/opt/local/libexec/llvm-19/bin/clang++ -DLDFLAGS=-L/opt/local/libexec/llvm-19/lib -DCPPFLAGS=-I/opt/local/libexec/llvm-19/include

I have also tried to use different paths, in case I am directing cmake to the wrong files, including CC=/opt/local/bin/aarch64-apple-darwin24-gcc-14.2.0, but I have still not found anything that works.

Has anyone else encountered this issue? Am I making any obvious mistakes? Any help would be greatly appreciated!


Solution

  • It turns out the answer was not specify a path for the different variables, as was suggested in the posts I had found during my search. The answer (as mentioned in this post linked by @RichardBarber) was simply to specify the compiler's name in the command:

    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCC="clang" -DCXX="clang++" -DOpenMP_C_FLAGS=-fopenmp=lomp -DOpenMP_C_LIB_NAMES="libomp"
    

    There was no need to assign the paths to any binaries or libraries.