4

How do I convince cmake (within CLion) I have the OpenMP headers available? I am trying to compile this project SCD and I receive the following error

...
[ 15%] Building CXX object tools/selector/CMakeFiles/selector.dir/source/main.cpp.o
[ 18%] Building CXX object tools/cc/CMakeFiles/cc.dir/source/main.cpp.o
/Users/buddha/github/buddha314/SCD/tools/wcc/source/main.cpp:22:10: fatal error: 'omp.h' file not found
#include <omp.h>
     ^

The CMakeLists.txt includes

SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp -DPROFILE ") 
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")    
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35
  • Where header `omp.h` is located on your system? – Tsyvarev Dec 10 '15 at 20:22
  • I used homebrew to install it, it was placed in ```/usr/local/Cellar/libiomp/20150701/include/libiomp/omp.h``` – Brian Dolan Dec 10 '15 at 21:29
  • So you need to include corresponded directory: `include_directories(/usr/local/Cellar/libiomp/20150701/include/libiomp)` – Tsyvarev Dec 10 '15 at 21:49
  • Thanks, my final was to add `set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")` in the `CMakesLists.txt` file, then add the flag `-D CMAKE_CXX_COMPILER=clang-omp++` to the cmake options in CLion. – Brian Dolan Dec 15 '15 at 16:05
  • So the final resolution is that default compiler doesn't support `openmp`. There are several questions about this situation, see e.g. [this one](http://stackoverflow.com/questions/25990296/how-to-include-omp-h-in-os-x). – Tsyvarev Dec 15 '15 at 16:40

1 Answers1

1

I think that your problem is not specific to CLion but the tool that is used for the building process (i.e CMake) . As already mentioned in this answer, there is a standard module for testing if the compiler supports OpenMP:

find_package(OpenMP)
if (OPENMP_FOUND)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
Community
  • 1
  • 1
pgmank
  • 5,303
  • 5
  • 36
  • 52
  • Out of many answers, this was the only one that worked for me. I think it's because other answers are meant for gcc compilers instead of clang on Mac OS. – Shane Sepac Mar 27 '21 at 18:37