【问题标题】:How to get clang with OpenMP working on MSVC 2015如何在 MSVC 2015 上使用 OpenMP 获得铿锵声
【发布时间】:2017-11-15 09:34:52
【问题描述】:

我尝试让 clang 5.0.0 为 Visual Studio 2015 工作,因为我需要 OpenMP 3.0 功能。我安装了clang编译器(不是没有任何openmp支持的vs2015版本)并使用cmake:

cmake_minimum_required(VERSION 2.8.10)
project(myproject)

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}")
endif()

include_directories("include")
add_library(libFoo STATIC Foo.cpp)

install(TARGETS Foo libFoo LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

当我现在尝试使用或不使用工具链 LLVM-vs2014 配置 MSVC 14 2015 Win64 构建时,我总是收到一个错误,即找不到 OpenMP:

The C compiler identification is Clang 5.0.0
The CXX compiler identification is Clang 5.0.0
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
Configuring done

使用的编译器似乎是正确的(安装 clang,而不是 Microsoft 版本),它自动检测 clang-cl 二进制文件,但 OpenMP 失败。 我尝试使用“指定本机编译器”手动指定编译器并获得相同的结果。它甚至选择了 clang-cl 版本而不是 clang++。

没有解决问题的相关答案:

【问题讨论】:

标签: c++ visual-studio-2015 clang openmp


【解决方案1】:

这确实有点棘手,并且 cmake 自动检测似乎效果不佳。有帮助的是

OpenMP_CXX_FLAGS="-Xclang -fopenmp"
OpenMP_C_FLAGS="-Xclang -fopenmp"

并确保 libomp.lib 在链接库中。

-Xclang 告诉 clang 二进制文件,以下选项是 clang 格式而不是 MSVC 格式,然后 -fopenmp 就是通常的 OpenMP 标志。但是,以任何其他方式设置它都不起作用。

一般模式是:-Xclang -clangFlag1 -Xclang -clangFlag2...。即每个 Clang Style 标志都需要自己的 -Xclang

【讨论】:

  • 在 cmake 选项中使用这些标志,它适用于 VS 2015。
  • 是的。添加-Xclang -fopenmp 有效。我不明白他们没有将 VS 的 OpenMP 映射到 clang-cl.exe 中的原因。
猜你喜欢
  • 2016-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多