gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 00:27:53 25 4
gpt4 key购买 nike

我尝试让 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com