简体   繁体   English

如何在MSVC 2015上使用OpenMP获得c声

[英]How to get clang with OpenMP working on MSVC 2015

I try to get clang 5.0.0 working for Visual Studio 2015, because I need OpenMP 3.0 features. 我尝试让clang 5.0.0适用于Visual Studio 2015,因为我需要OpenMP 3.0功能。 I installed the clang compiler (not the vs2015 version which does not have any openmp support) and use cmake: 我安装了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)

When I now try to configure a MSVC 14 2015 Win64 build with or without toolchain LLVM-vs2014 I always get an error, that OpenMP is not found: 现在,当我尝试配置带或不带工具链LLVM-vs2014MSVC 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

The used compiler seems to be the right one (Installed clang, not the Microsoft version), it autodetects the clang-cl binary, but OpenMP fails. 使用的编译器似乎是正确的版本(已安装clang,而不是Microsoft版本),它可以自动检测clang-cl二进制文件,但是OpenMP失败。 I tried to manually specify the compilers with "specify native compilers" and get the same result. 我尝试使用“指定本机编译器”手动指定编译器,并获得相同的结果。 It even selects the clang-cl version instead of clang++. 它甚至选择clang-cl版本而不是clang ++。

Related Answer, which does not solve the problem: 相关答案,不能解决问题:

It is really a bit tricky and the cmake autodetection doesn't seem to work very well. 这确实有点棘手,并且cmake自动检测似乎不能很好地工作。 What helped is 帮助的是

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

And making sure that libomp.lib is in the link libraries. 并确保libomp.lib在链接库中。

-Xclang tells the clang binary, that the following options are in clang format and not in MSVC format and -fopenmp is then just the usual OpenMP flag. -Xclang告诉clang二进制文件,以下选项是clang格式而不是MSVC格式,因此-fopenmp只是通常的OpenMP标志。 Setting it any other way did not work, though. 但是,以任何其他方式设置它均无效。

The general pattern is: -Xclang -clangFlag1 -Xclang -clangFlag2... . 常规模式为: -Xclang -clangFlag1 -Xclang -clangFlag2... Namely each Clang Style flag requires its own -Xclang . 也就是说,每个Clang Style标志都需要其自己的-Xclang

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM