• <bdo id='dyedr'></bdo><ul id='dyedr'></ul>
  • <legend id='dyedr'><style id='dyedr'><dir id='dyedr'><q id='dyedr'></q></dir></style></legend>

  • <tfoot id='dyedr'></tfoot>

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

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

        使用 CMake、Clang 和 Ninja 在 Windows 上构建 C++ 项目

        Building c++ project on Windows with CMake, Clang and Ninja(使用 CMake、Clang 和 Ninja 在 Windows 上构建 C++ 项目)
        • <bdo id='k2IZ2'></bdo><ul id='k2IZ2'></ul>
          <tfoot id='k2IZ2'></tfoot>

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

            <tbody id='k2IZ2'></tbody>
              <legend id='k2IZ2'><style id='k2IZ2'><dir id='k2IZ2'><q id='k2IZ2'></q></dir></style></legend>

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

                  本文介绍了使用 CMake、Clang 和 Ninja 在 Windows 上构建 C++ 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前在 Windows 上安装了 cmake、clang 和 ninja.我正在尝试使用 CMake 生成 ninja 构建文件来编译一个非常简单的 hello world 程序.

                  I currently have cmake, clang and ninja installed on windows. I am trying to use CMake to generate a ninja build file to compile a very simple hello world program.

                  我的 CMakeLists.txt 看起来像这样:

                  My CMakeLists.txt looks like this:

                  cmake_minimum_required(VERSION 2.8)
                  project(test_project)
                  add_executable(main main.cpp)
                  

                  main.cpp 是一个简单的 hello world 程序.

                  main.cpp is a simple hello world program.

                  在命令行上我运行这个:cmake -G Ninja .. 并且我得到以下错误:

                  On the command line I run this: cmake -G Ninja .. and I get the following errors:

                  -- The C compiler identification is Clang 3.5.0
                  clang.exe: error: no such file or directory: '/nologo'
                  clang.exe: error: no such file or directory: '/showIncludes'
                  -- The CXX compiler identification is Clang 3.5.0
                  clang.exe: error: no such file or directory: '/nologo'
                  clang.exe: error: no such file or directory: '/showIncludes'
                  -- Check for working C compiler using: Ninja
                  -- Check for working C compiler using: Ninja -- broken
                  CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
                    The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
                    not able to compile a simple test program.
                  
                    It fails with the following output:
                  
                     Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
                  
                  
                  
                    Run Build Command:C:/ninja/ninja.exe cmTryCompileExec375034429
                  
                    [1/2] Building C object
                    CMakeFilescmTryCompileExec375034429.dir	estCCompiler.c.obj
                  
                  
                    [2/2] Linking C executable cmTryCompileExec375034429.exe
                  
                  
                    FAILED: cmd.exe /c cd .  &&
                    C:llvm_buildRelWithDebInfoinclang.exe
                    CMakeFilescmTryCompileExec375034429.dir	estCCompiler.c.obj -o
                    cmTryCompileExec375034429.exe && cd .
                  
                  
                    clang.exe: error: unable to execute command: program not executable
                  
                  
                  
                    clang.exe: error: linker command failed with exit code 1 (use -v to see
                    invocation)
                  
                  
                  
                    ninja: build stopped: subcommand failed.
                  
                  
                  
                  
                  
                  
                    CMake will not be able to correctly generate this project.
                  Call Stack (most recent call first):
                    CMakeLists.txt:2 (project)
                  
                  
                  -- Configuring incomplete, errors occurred!
                  See also "C:/test_proj/build/CMakeFiles/CMakeOutput.log".
                  See also "C:/test_proj/build/CMakeFiles/CMakeError.log".
                  

                  CMakeError.log 文件如下所示:

                  Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
                  Compiler: C:/llvm_build/RelWithDebInfo/bin/clang.exe 
                  Build flags: 
                  Id flags: 
                  
                  The output was:
                  1
                  clang.exe: error: unable to execute command: program not executable
                  clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
                  
                  
                  Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
                  Compiler: C:/llvm_build/RelWithDebInfo/bin/clang++.exe 
                  Build flags: 
                  Id flags: 
                  
                  The output was:
                  1
                  clang++.exe: error: unable to execute command: program not executable
                  clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
                  
                  
                  Determining if the C compiler works failed with the following output:
                  Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
                  
                  Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2120850158
                  [1/2] Building C object CMakeFilescmTryCompileExec2120850158.dir	estCCompiler.c.obj
                  
                  [2/2] Linking C executable cmTryCompileExec2120850158.exe
                  
                  FAILED: cmd.exe /c cd . && C:llvm_buildRelWithDebInfoinclang.exe     CMakeFilescmTryCompileExec2120850158.dir	estCCompiler.c.obj  -o cmTryCompileExec2120850158.exe   && cd .
                  
                  clang.exe: error: unable to execute command: program not executable
                  
                  
                  clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
                  
                  
                  ninja: build stopped: subcommand failed.
                  

                  看来 cmake 正在尝试使用 Windows 选项 /nologo/showIncludes 来测试 clang.我不知道如何告诉 cmake 传递正确的参数.

                  It appears that cmake is trying to test clang with windows options /nologo and /showIncludes. I cannot figure out how to tell cmake to pass the proper arguments.

                  FWIW 我运行的是 64 位 Windows 7

                  FWIW I'm running 64bit Windows 7

                  所以我查看了内置的 cmake 文件,我发现 CMakeClDeps.cmake 文件是添加 /nologo/showIncludes 选项的罪魁祸首.看来,如果我将 Clang 设置为编译器,那么 cmake 认为 Visual Studio 是编译器(它将 MSVC_C_ARCHITECTURE_ID 设置为 x86).

                  So I looked through the built in cmake files and I found that the CMakeClDeps.cmake file was the culprit for adding the /nologo /showIncludes options. It appears that if I set Clang as the compiler then cmake thinks that visual studio is the compiler (it sets MSVC_C_ARCHITECTURE_ID to x86).

                  我删除了 CMakeDetermineCompilerId.cmake 中设置 MSVC_C_ARCHITECTURE_ID 的行,再次尝试后,我收到以下错误:

                  I removed the line in CMakeDetermineCompilerId.cmake that sets MSVC_C_ARCHITECTURE_ID and after trying again I get the following errors:

                  -- The C compiler identification is Clang 3.5.0
                  -- The CXX compiler identification is Clang 3.5.0
                  -- Check for working C compiler using: Ninja
                  -- Check for working C compiler using: Ninja -- broken
                  CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
                    The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
                    not able to compile a simple test program.
                  
                    It fails with the following output:
                  
                     Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
                  
                  
                  
                    Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2815594422
                  
                    [1/2] Building C object
                    CMakeFilescmTryCompileExec2815594422.dir	estCCompiler.c.obj
                  
                  
                    [2/2] Linking C executable cmTryCompileExec2815594422.exe
                  
                  
                    FAILED: cmd.exe /c cd .  &&
                    C:llvm_buildRelWithDebInfoinclang.exe
                    CMakeFilescmTryCompileExec2815594422.dir	estCCompiler.c.obj -o
                    cmTryCompileExec2815594422.exe && cd .
                  
                  
                    clang.exe: error: unable to execute command: program not executable
                  
                  
                  
                    clang.exe: error: linker command failed with exit code 1 (use -v to see
                    invocation)
                  
                  
                  
                    ninja: build stopped: subcommand failed.
                  
                  
                  
                  
                  
                  
                    CMake will not be able to correctly generate this project.
                  Call Stack (most recent call first):
                    CMakeLists.txt:2 (project)
                  
                  
                  -- Configuring incomplete, errors occurred!
                  See also "C:/test_proj/build/CMakeFiles/CMakeOutput.log".
                  See also "C:/test_proj/build/CMakeFiles/CMakeError.log".
                  

                  推荐答案

                  不知道它是否有帮助,但我遇到了同样的错误.现在我可以在 Windows 上使用 clang(3.7.1)/ninja(1.6)/cmake(3.4.1) 进行编译,在构建目录中执行以下操作:

                  Don't know if it can be helpful but I had the same error. Now I can compile with clang(3.7.1)/ninja(1.6)/cmake(3.4.1) on Windows performing the following actions in a build directory:

                  1. 加载相关的 vcvarsXX.bat 文件(例如 "VCvcvarsall.bat" x86)
                  2. 将 CC 和 CXX 设置为 clang-cl(而不是 clangclang++)
                  3. 运行 cmake -G Ninja
                  4. 运行 cmake --build .
                  1. load the relevant vcvarsXX.bat file (e.g. "<Your Visual Studio location>VCvcvarsall.bat" x86)
                  2. set both CC and CXX to clang-cl (instead of clang and clang++)
                  3. run cmake -G Ninja <project>
                  4. run cmake --build .

                  这篇关于使用 CMake、Clang 和 Ninja 在 Windows 上构建 C++ 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                  <legend id='dmipb'><style id='dmipb'><dir id='dmipb'><q id='dmipb'></q></dir></style></legend>

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

                          <tbody id='dmipb'></tbody>

                        1. <small id='dmipb'></small><noframes id='dmipb'>