我尝试让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
使用过的编译器似乎是正确的(Installed clang,而不是Microsoft版本),它会自动检测clang-cl二进制文件,但OpenMP失败。 我尝试用"指定本机编译器"来手动指定编译器。并得到相同的结果。它甚至选择了clang-cl版本而不是clang ++。
相关答案,但没有解决问题:
答案 0 :(得分:4)
这真的有点棘手,而且cmake自动检测似乎并不能很好地工作。有什么帮助
OpenMP_CXX_FLAGS="-Xclang -fopenmp"
OpenMP_C_FLAGS="-Xclang -fopenmp"
确保libomp.lib
在链接库中。
-Xclang
告诉clang二进制文件,以下选项是clang格式而不是MSVC格式,-fopenmp只是通常的OpenMP标志。但是,任何其他方式设置它都不起作用。
一般模式是:-Xclang -clangFlag1 -Xclang -clangFlag2...
。即每个Clang Style标志都需要自己的-Xclang
。