<i id='WK62m'><tr id='WK62m'><dt id='WK62m'><q id='WK62m'><span id='WK62m'><b id='WK62m'><form id='WK62m'><ins id='WK62m'></ins><ul id='WK62m'></ul><sub id='WK62m'></sub></form><legend id='WK62m'></legend><bdo id='WK62m'><pre id='WK62m'><center id='WK62m'></center></pre></bdo></b><th id='WK62m'></th></span></q></dt></tr></i><div id='WK62m'><tfoot id='WK62m'></tfoot><dl id='WK62m'><fieldset id='WK62m'></fieldset></dl></div>

      <small id='WK62m'></small><noframes id='WK62m'>

        <bdo id='WK62m'></bdo><ul id='WK62m'></ul>

      <legend id='WK62m'><style id='WK62m'><dir id='WK62m'><q id='WK62m'></q></dir></style></legend>

      1. <tfoot id='WK62m'></tfoot>

        如何告诉 CMake 在 Windows 上使用 Clang?

        时间:2023-08-28

              <tbody id='Qs9u6'></tbody>

            <small id='Qs9u6'></small><noframes id='Qs9u6'>

            <tfoot id='Qs9u6'></tfoot>

                <i id='Qs9u6'><tr id='Qs9u6'><dt id='Qs9u6'><q id='Qs9u6'><span id='Qs9u6'><b id='Qs9u6'><form id='Qs9u6'><ins id='Qs9u6'></ins><ul id='Qs9u6'></ul><sub id='Qs9u6'></sub></form><legend id='Qs9u6'></legend><bdo id='Qs9u6'><pre id='Qs9u6'><center id='Qs9u6'></center></pre></bdo></b><th id='Qs9u6'></th></span></q></dt></tr></i><div id='Qs9u6'><tfoot id='Qs9u6'></tfoot><dl id='Qs9u6'><fieldset id='Qs9u6'></fieldset></dl></div>

                <legend id='Qs9u6'><style id='Qs9u6'><dir id='Qs9u6'><q id='Qs9u6'></q></dir></style></legend>
                  <bdo id='Qs9u6'></bdo><ul id='Qs9u6'></ul>
                  本文介绍了如何告诉 CMake 在 Windows 上使用 Clang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 CMake 构建的 C++ 项目.我通常在 OSX 上构建,但现在我也在尝试让 Windows 版本也能正常工作.出于兼容性原因,我想在 Windows 上使用 Clang.

                  I have a C++ project that builds using CMake. I usually build on OSX but now I am trying to get a Windows version working too. I would like to use Clang on Windows for compatibility reasons.

                  我从 LLVM 安装了预编译的 Clang 3.8 二进制文件:

                  I installed the pre-compiled Clang 3.8 binary from LLVM:

                  C:Program FilesLLVMinclang.exe
                  C:Program FilesLLVMinclang++.exe
                  

                  它也安装在我的 PATH 上:

                  It is also installed on my PATH:

                  >clang++
                  clang++.exe: error: no input files
                  

                  我有两个问题:

                  1. 当我调用 cmake --build 时,如何告诉 CMake 使用 clang++?
                  2. 如何在构建 CMake 配置的编译器之前检查?
                  1. How do I tell CMake to use clang++ when I call cmake --build?
                  2. How can I check before building which compiler CMake is configured with?

                  推荐答案

                  除了 Clang 编译器本身之外,您还需要一个适用于 Windows 的构建/链接环境.

                  You also need - in addition to the Clang compilers itself - an build/link environment for Windows.

                  最新的 CMake 3.6 版本确实在 Windows 上集成了多个受支持的 Clang 构建环境(例如 Visual Studio、Cygwin;请参阅 发行说明).

                  The latest CMake 3.6 builds do have several integrated supported Clang build environments on Windows (e.g. Visual Studio, Cygwin; see Release Notes).

                  我刚刚用

                  • LLVM-3.9.0-r273898-win32.exe 来自 http://llvm.org/builds/
                  • cmake-3.6.0-rc4-win64-x64.msi 来自 https://cmake.org/download/
                  • Microsoft VS2015 社区版 14.0.23107.0 版

                  全部安装到其标准路径,并在全局 PATH 环境中使用它们的 bin 目录.

                  All installed to their standard paths with their bin directories in the global PATH environment.

                  您需要知道的部分是使用 CMake -T"LLVM-vs2014" 命令行选项设置正确的工具集.在配置过程中,CMake 会告诉你它找到/采用了哪个编译器.

                  The part you need to know is setting the right toolset with the CMake -T"LLVM-vs2014" command line option. During the configuration process CMake will let you know which compiler it has found/taken.

                  CMakeLists.txt

                  cmake_minimum_required(VERSION 3.6)
                  
                  project(HelloWorld)
                  
                  file(
                      WRITE main.cpp 
                          "#include <iostream>
                  "
                          "int main() { std::cout << "Hello World!" << std::endl; return 0; }"
                  )
                  add_executable(${PROJECT_NAME} main.cpp)
                  

                  Windows 控制台

                  ...> mkdir VS2015
                  ...> cd VS2015
                  ...VS2015> cmake -G"Visual Studio 14 2015" -T"LLVM-vs2014" ..
                  -- The C compiler identification is Clang 3.9.0
                  -- The CXX compiler identification is Clang 3.9.0
                  -- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
                  -- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe -- works
                  -- Detecting C compiler ABI info
                  -- Detecting C compiler ABI info - done
                  -- Check for working CXX compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
                  -- Check for working CXX compiler: C:/Program Files (x86)/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
                  -- Configuring done
                  -- Generating done
                  -- Build files have been written to: .../VS2015
                  ...VS2015> cmake --build . 
                  Microsoft (R)-Buildmodul, Version 14.0.23107.0
                  [...]
                  ...VS2015> DebugHelloWorld.exe
                  Hello World!
                  

                  安装提示

                  请注意,我在设置过程中已将 LLVM 添加到我的搜索路径中:

                  Please note that I have added LLVM to my search paths during setup:

                  并且您可以在任何 VS 项目的属性页面中交叉检查可用的平台工具集":

                  And you can crosscheck the available "Platform Toolsets" in any VS project's property page:

                  参考资料

                  • 什么是-D定义告诉Cmake在哪里可以找到nmake?
                  • Clang 链接器?
                  • 使用 CMake 在 GCC 和 Clang/LLVM 之间切换

                  这篇关于如何告诉 CMake 在 Windows 上使用 Clang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:CMake 找不到 Visual C++ 编译器 下一篇:CMake 无法使用 C++ 确定链接器语言

                  相关文章

                  • <bdo id='5F5jD'></bdo><ul id='5F5jD'></ul>

                  <small id='5F5jD'></small><noframes id='5F5jD'>

                  <i id='5F5jD'><tr id='5F5jD'><dt id='5F5jD'><q id='5F5jD'><span id='5F5jD'><b id='5F5jD'><form id='5F5jD'><ins id='5F5jD'></ins><ul id='5F5jD'></ul><sub id='5F5jD'></sub></form><legend id='5F5jD'></legend><bdo id='5F5jD'><pre id='5F5jD'><center id='5F5jD'></center></pre></bdo></b><th id='5F5jD'></th></span></q></dt></tr></i><div id='5F5jD'><tfoot id='5F5jD'></tfoot><dl id='5F5jD'><fieldset id='5F5jD'></fieldset></dl></div>
                    <legend id='5F5jD'><style id='5F5jD'><dir id='5F5jD'><q id='5F5jD'></q></dir></style></legend>

                    1. <tfoot id='5F5jD'></tfoot>