Skip to content

FindOpenMP: Fails when using LLVM clang

Trying to build the following simple program on Windows 11, LLVM clang 18.1.3 and cmake 3.30.3 results in failure to find OpenMP. Might be related to an older #19404 (closed). Building with MSVC has not such problems.

cmake_minimum_required(VERSION 3.20)
project(test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(OpenMP REQUIRED)

add_executable(test main.cpp)
target_link_libraries(test PRIVATE
  OpenMP::OpenMP_CXX
)
#include "omp.h"
#include <cstdio>

auto main() -> int {
  const auto threads = omp_get_max_threads();
  printf("Threads: %d\n", threads);
  return 0;
}

The output:

cmake "-DCMAKE_C_COMPILER:FILEPATH=D:\LLVM\bin\clang.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=D:\LLVM\bin\clang++.exe" -S. -Bbuild -G Ninja
-- The CXX compiler identification is Clang 18.1.3 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.30/Modules/FindOpenMP.cmake:600 (find_package_handle_standard_args)
  CMakeLists.txt:10 (find_package)


-- Configuring incomplete, errors occurred!
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information