Reputation: 581
I am trying to use OpenMP 4.5 on Windows but MSVC seems to not support OpenMP > 2.0
I found that Clang supports OpenMP 4.5 but I can't make it work on Windows.
I have Visual Studio 2017, Clang 8.0.0 and CMake 3.13 installed.
To build my CMake project, I call:
cmake .. -G Ninja -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_LINKER:PATH="C:/Program Files/LLVM/bin/lld-link.exe"
But it cannot find OpenMP :
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
If I build using clang alone (clang.exe & clang++.exe instead of clang-cl.exe), it finds Clang's OpenMP lib (OpenMP 5.0)
If I build using MSVC alone, it finds OpenMP 2.0
But using clang-cl.exe, it does not find OpenMP (neither version)
Is there a way to get OpenMP 4.5 working on Windows ?
Thanks,
Upvotes: 0
Views: 1364
Reputation: 18333
You haven't posted an example of your CMake, so I'm going off of conjecture here. If you are using find_package(OpenMP REQUIRED)
, I have also received similar errors when using clang-cl
from Visual Studio. There are known limitations with CMake's FindOpenMP.cmake
module, as well as some lack of support the clang-cl
side. There are other answers on this site suggesting to populate the CMake OpenMP_
variables manually, but this seems backwards, and I only have limited success. I was able to successfully run CMake then compile my applications with MSVC+Clang by avoiding the use of find_package
and (unfortunately) hard-coding the path to the OpenMP libraries for now:
cmake_minimum_required (VERSION 3.10)
project(MyOpenMPTest LANGUAGES CXX)
set(OpenMP_LIBRARY_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/Llvm/lib")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# Tell CMake where to find the OpenMP libraries.
link_directories(${OpenMP_LIBRARY_DIR})
# Library
add_library(MyLibrary SHARED MyExample.h MyExample.cpp)
# Link in the OpenMP libraries.
target_link_libraries(MyLibrary PUBLIC libomp libiomp5md)
# Executable
add_executable(MyOpenMpTest MyOpenMpTest .cpp)
target_link_libraries(MyOpenMpTest MyLibrary)
Hopefully, the folks at CMake and LLVM will get this issue worked out soon and FindOpenMP.cmake
can be used more reliably.
Upvotes: 1