4

I'm currently trying to find OpenMP using cmake.

Below is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)

set(CMAKE_C_STANDARD 11)

set(GCC_COMPILE_FLAGS -Wall -Werror -Wvla -O0)

SET(CMAKE_BUILD_TYPE Debug)

# Find 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}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

I'm using Ubuntu 20.04 and I have libomp-dev installed as shown below:

libomp-dev is already the newest version (1:10.0-50~exp1).

When I set gcc as my compiler, cmake has no issues finding OpenMP.

However, when I use clang-12 as my compiler by specifying the following cmake flags:

-DCMAKE_C_COMPILER=/usr/bin/clang-12 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12

I get the following "cannot find OpenMP error" from cmake:

CMake Error at cmake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenMP_C

How should I set up my CMakeLists.txt file so that OpenMP can be found when using clang as my compiler?

1
  • 1
    According to the list of files provided by libomp-dev package, it provides OpenMP support for clang-10. OpenMP support for clang-12 should come with clang-12 itself. Commented Nov 1, 2021 at 15:39

1 Answer 1

9

As @Tsyvarev pointed out, since I had libomp-dev version 10 installed, CMake would be able to find OpenMP if I used clang-10.

So in order for me to use OpenMP with clang-12, I had to make sure that libomp-dev version 12 was installed, which I did using the following shell command:

sudo apt -y install libomp-12-dev

Now CMake has no issues finding OpenMP when I use clang-12 as my compiler.

Sign up to request clarification or add additional context in comments.

1 Comment

indeed, it also solved my problem with clang-13! Yeay

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.