CMake can't find OpenMP on Mojave
Having updated my mac from High Sierra to Mojave 10.14 (18A391), CMake is now unable to find the OpenMP symbols using the default Clang compiler.
I have installed libomp
from Homebrew, and I am able to compile and run main.cpp
hereunder using
c++ -Xpreprocessor -fopenmp -lomp main.cpp
Running the program prints out 4
, which is the expected behavior. However, trying to use cmake
to configure the exemple fails as OpenMP cannot be found. I have attached the relevant code snippets.
// main.cpp
#include <omp.h>
#include <iostream>
int main(){
std::cout << omp_get_max_threads() << std::endl;
return 1;
}
// CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(main CXX)
add_executable(main main.cpp)
find_package(OpenMP REQUIRED)
target_link_libraries(main PRIVATE OpenMP::OpenMP_CXX)
// CMake trace
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
// insert content from CMake error trace
-- Configuring incomplete, errors occurred!
See also "/Users/bbercovici/Desktop/testOmp/build/CMakeFiles/CMakeOutput.log".
// CMake error trace
CMake Error at /usr/local/Cellar/cmake/3.12.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.12.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:382 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.12.3/share/cmake/Modules/FindOpenMP.cmake:466 (find_package_handle_standard_args)
CMakeLists.txt:6 (find_package)
Edited by bbercovici