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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With