all*_*llo 2 c++ openmp clang visual-studio-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)
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试配置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
Run Code Online (Sandbox Code Playgroud)
使用的编译器似乎是正确的编译器(已安装clang,不是Microsoft版本),它可以自动检测clang-cl二进制文件,但是OpenMP失败。我尝试使用“指定本机编译器”手动指定编译器,并获得相同的结果。它甚至选择clang-cl版本而不是clang ++。
相关答案,不能解决问题:
这确实有点棘手,并且cmake自动检测似乎不能很好地工作。帮助的是
OpenMP_CXX_FLAGS="-Xclang -fopenmp"
OpenMP_C_FLAGS="-Xclang -fopenmp"
Run Code Online (Sandbox Code Playgroud)
并确保它libomp.lib在链接库中。
-Xclang告诉clang二进制文件,以下选项是clang格式,而不是MSVC格式,因此-fopenmp只是通常的OpenMP标志。但是,以任何其他方式设置它均无效。
常规模式为:-Xclang -clangFlag1 -Xclang -clangFlag2...。也就是说,每个Clang Style标志都需要自己的标志-Xclang。