14

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.

2
  • The files associated to this folder are in C++. Sorry. I edited Commented Feb 16, 2018 at 13:06
  • I have the same problem in the latest Mac OSX Mojave 10.14.4 with CMake 3.14.1. CMake Error at /usr/local/Cellar/cmake/3.14.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) Commented Apr 14, 2019 at 8:50

6 Answers 6

14

This is because the Xcode clang not support, use system clang instead.

method 1: set env variables, then run cmake https://gist.github.com/svenevs/f00ed3898d2af6248921b63254aa8cc1

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

method2: set env variables in CMakeLists.txt

message(STATUS "set env var")
set(ENV{CC} "/usr/local/opt/llvm/bin/clang")
set(ENV{CXX} "/usr/local/opt/llvm/bin/clang++")
set(ENV{LDFLAGS} "-L/usr/local/opt/llvm/lib")
set(ENV{CPPFLAGS} "-I/usr/local/opt/llvm/include")

method3: change var in CMakeLists.txt

message(STATUS "set compipler")
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/5.0.1/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/5.0.1/include")

set(OPENMP_LIBRARIES "/usr/local/opt/llvm/lib")
link_directories(${OPENMP_LIBRARIES})

method4. change env variable when run cmake

cmake .. -DCC=xxx -DCXX=xxx -DLDFLAGS="" -DCPPFLAGS=""
Sign up to request clarification or add additional context in comments.

1 Comment

I wonder why? Can any one give a hint?
10

Need to set OpenMP_ROOT on macOS to point to libomp. For macOS, first do:

brew install libomp

and set in ~/.zshrc

export OpenMP_ROOT=$(brew --prefix)/opt/libomp

1 Comment

On M3 mac, that was the only solution that worked for me. Thank you!
9

Find OpenMP

Despite the other answers so far, one can use the system compiler.

if(APPLE)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
    set(OpenMP_C "${CMAKE_C_COMPILER}" CACHE STRING "" FORCE)
    set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
    set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
    set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
    set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
    set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(OpenMP_CXX "${CMAKE_CXX_COMPILER}" CACHE STRING "" FORCE)
  set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
  set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
  set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
  set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
  set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
endif()
endif()

3 Comments

Hi, welcome to Stack Overflow. When answering a question that already has many answers, please be sure to add some additional insight into why the response you're providing is substantive and not simply echoing what's already been vetted by the original poster. This is especially important in "code-only" answers such as the one you've provided.
I would have thought that it was clear why this is a substantive response. It is the only solution that doesn't require downloading and maintaining a entirely different clang/llvm pair in parallel with the Apple clang/llvm.
thanks a lot for this much better answer!
5

I ran into this issue on an ARM-based MacOS machine and installing libomp fixed it:

arch -x86_64 brew install libomp

1 Comment

This requires an installation of homebrew under the x86_64 architecture, which can further complicate things
3

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++

Comments

2

Using @lbsweek hint:

It worked for me after mapping where brew was installing llvm.

Which is "/opt/homebrew/Cellar/llvm/{version}"

Once you know it, you can map OpenMP_C_FLAGS OpenMP_C_LIB_NAMES with:

export CC=/opt/homebrew/Cellar/llvm/15.0.6/bin/clang
export CXX=/opt/homebrew/Cellar/llvm/15.0.6/bin/clang++
export LDFLAGS="-L/opt/homebrew/Cellar/llvm/15.0.6/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/llvm/15.0.6/include"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.