c++ - 如何在 MSVC 2015 上使用 OpenMP 获得 clang

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

我尝试让 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 失败。 我尝试使用“指定 native 编译器”手动指定编译器并获得相同的结果。它甚至选择 clang-cl 版本而不是 clang++。

相关回答,没有解决问题:

最佳答案

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

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

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

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

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

关于c++ - 如何在 MSVC 2015 上使用 OpenMP 获得 clang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47303810/

相关文章:

debugging - 在 Debug模式下链接 v8 引擎静态库时出现 clang 警告 "could not find object file symbol for symbol"

c++ - Ubuntu 不提供包含 uint24_t 类型的 Clang 的 stdint

c++ - 如何使用 pthreads 对类成员函数进行多线程处理?

c++ - 在 EBNF 或 GNU Bison 语法中使用方括号/圆括号

c++ - 尝试写入文件但只打印一次

c++ - 无法在 Visual Studio Community 2015 中编译基本程序(LNK2019 - MSVCRTD.lib)

javascript - Visual Studio 2015 Update 2 中的 TypeScript 模块 - 'require' 未定义

c++ - CMake添加到Clang的包含路径

c++ - 这两种结构的写法是一样的吗?

c++ - Raspberry Pi 优化的 backtrace()