cmake没有拿起clang ++并且总是在Windows上使用visual studio

时间:2018-04-20 15:18:14

标签: windows cmake clang clang++

我有视觉工作室2017和clang都安装在64位Windows 10 PC中。

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix

我尝试使用clang运行cmake:

-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

但是cmake总是选择visual studio而不是clang作为c ++编译器。

-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.13.26131.1
-- The CXX compiler identification is MSVC 19.13.26131.

有没有办法在没有像visual studio这样的工具的情况下在cmake中使用clang作为我的c ++编译器?

1 个答案:

答案 0 :(得分:0)

如果您希望将VisualStudio 201x与clang / c2编译器一起使用,请忘记linux / mac方法(适用于mingw / msys等)。无需使用这些CMAKE_C ?? _ COMPILER变量。

尝试例如。

cd build
cmake -G"Visual Studio 15 2017" -T "v141_clang_c2" <SRC_DIR>

当您打开任何C ++项目然后查看Propertiese菜单时,可以观察到可用工具集的列表 - &gt;一般:“平台工具集”组合框列表

或者使用LLVM snapshot build页面定义要在上述命令中使用的工具集名称,例如LLVM-vs2013。

示例输出:

C:\work\build>cmake -G"Visual Studio 15 2017" -T"v141_clang_c2" <SRC>
-- The C compiler identification is Clang 3.8.0
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/ClangC2/14.10.25903/bin/HostX86/clang.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/ClangC2/14.10.25903/bin/HostX86/clang.exe -- works
-- Detecting C compiler ABI info
....