如何在MSVC 2015上使用OpenMP获得c声 [英] How to get clang with OpenMP working on MSVC 2015

查看:163
本文介绍了如何在MSVC 2015上使用OpenMP获得c声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to get clang 5.0.0 working for Visual Studio 2015, because I need OpenMP 3.0 features. I installed the clang compiler (not the vs2015 version which does not have any openmp support) and use 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-vs2014MSVC 14 2015 Win64构建时,总是出现错误,找不到OpenMP:

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:

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 ++.

The used compiler seems to be the right one (Installed clang, not the Microsoft version), it autodetects the clang-cl binary, but OpenMP fails. 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++.

相关答案,不能解决问题:

Related Answer, which does not solve the problem:

  • Compiling C code with openmp using clang-cl - Recent clang has libomp.lib and libiomp5.dll included

推荐答案

这确实有点棘手,并且cmake自动检测似乎不能很好地工作.有帮助的是

It is really a bit tricky and the cmake autodetection doesn't seem to work very well. What helped is

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

并确保链接库中包含libomp.lib.

-Xclang告诉clang二进制文件,以下选项是clang格式而不是MSVC格式,因此-fopenmp只是通常的OpenMP标志.但是,以其他任何方式设置它均无效.

-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. Setting it any other way did not work, though.

一般模式是:-Xclang -clangFlag1 -Xclang -clangFlag2....也就是说,每个Clang Style标志都需要自己的-Xclang.

The general pattern is: -Xclang -clangFlag1 -Xclang -clangFlag2.... Namely each Clang Style flag requires its own -Xclang.

这篇关于如何在MSVC 2015上使用OpenMP获得c声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆