Search code examples
c++macoscmakeopenmp

missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES


I'm struggling in compiling a project using OpenMP on Mac OSX. The error is:

CMake Error at /usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call stack most recent call first) 
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindOpenMP.cmake:447 (find_package_handle_standard_args)
libRORPO/CMakeLists.txt:7 (find_package)

The CMakeLists file associated to the search of OpenMP in the project is the following:

# RORPO Lib

project(libRORPO)
cmake_minimum_required(VERSION 2.8)

# FIND OPENMP
find_package( OpenMP REQUIRED)
if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} 
         ${OpenMP_EXE_LINKER_FLAGS}")
endif()

# ADD FILES
file(GLOB_RECURSE RORPO_HEADERS *.hpp *.h)
file(GLOB_RECURSE RORPO_SOURCES *.c)

add_library(RORPO ${LIB_TYPE} ${RORPO_SOURCES} ${RORPO_HEADERS})

install( FILES ${RORPO_HEADERS} DESTINATION include/libRORPO)
install( TARGETS RORPO DESTINATION lib)

I verified if the OpenMP installation runs well using either gcc-7 and Clang-omp. I've searched for similar bugs. Responses pointed that there is a recent package in cmake that allows the finding of OpenMp. I reinstalled CMAKE to have a recent version but it still doesn't work. I'm not expert in cmake configurations.., I would appreciate if you can guide me.


Solution

  • I found a solution porposed in : http://stechschulte.net/2016/03/20/openmp-osx-cmake.html

    The trick is that cmake must be run with the CC and CXX environment variables pointing to clang-omp:

    CC=clang-omp CXX=clang-omp++ cmake
    

    Note that clang-omp and clang-omp++ have to be defined after installing llvm via:

    brew install llvm
    

    and create two symlink:

    ln -s /usr/local/opt/llvm/bin/clang /usr/local/bin/clang-omp
    ln -s /usr/local/opt/llvm/bin/clang++ /usr/local/bin/clang-omp++