如何与 OpenMP 在 MSVC 2015 上合作
How to get clang with OpenMP working on MSVC 2015
我尝试让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)
当我现在尝试配置带有或不带工具链的MSVC 14 2015 Win64
构建时LLVM-vs2014
我总是收到一个错误,即找不到 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++。
相关答案,这不能解决问题:
- 使用 clang-cl 使用 openmp 编译 C 代码 - 最近的 clang 包含 libomp.lib 和 libiomp5.dll
这真的有点棘手,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
。
相关文章:
- 为什么使用 <uint8_t>MSVC 2015 编译器的 std::vector::insert 比 std::copy 快 5 倍?
- 链接错误时,使用CLION/CMAKE/MSVC 2015编译WIN32应用程序
- 将 QT Creator 5.8 与 MSVC 2015 编译器配合使用
- Visual C++ 模板代码适用于 MSVC 2015,但不适用于 2017
- MSVC 2015-我程序中的SSE编译器错误或错误/未定义的行为
- 如何与 OpenMP 在 MSVC 2015 上合作
- 使用MSVC 2015上的Windows上使用Google测试
- MSVC 2015无法编译Constexpr Atan
- visual C++默认特殊成员函数的多个版本——MSVC 2015中的错误
- MSVC 2015 - 自定义迭代器的 std::for_each 中的编译器错误(仅在调试中时)
- 对于Clang和Codegen的MSVC 2015,我如何让ast dump工作
- QT 5.7 MSVC 2015静态构建不工作
- 使用MSVC 2013和2015,使用CMake和ExternalProject_Add,通过引用导出的成员函数传递st
- MSVC 2015 /Wall有很多没用的信息
- 在MSVC 2015中,std::async抛出异常的奇怪行为
- 确认MSVC 2015 RC中有关分配器的标准库Bug
- 与MSVC 2015比较bool和int引用时发出警告
- gcc C++14与msvc++2015中的级联宏
- Qt + MSVC 2015 + Firebase SDK v1.0.0
- MSVC 2015 为 std::vector 选择不正确的构造函数重载