Windows 上的 CMake -G Ninja 指定 x64

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31262342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:09:51  来源:igfitidea点击:

CMake -G Ninja on Windows specify x64

windowscmake64-bitx86-64ninja

提问by xren

I am using CMake on Windows with Ninja generator

我在 Windows 上使用 CMake 和 Ninja 生成器

cmake -G Ninja ..

This uses the default Windows x86 toolchain. How to specify x64 using the Ninja generator?

这使用默认的 Windows x86 工具链。如何使用 Ninja 生成器指定 x64?

PS: I know how to generate x64 with Visual Studio

PS:我知道如何使用 Visual Studio 生成 x64

cmake -G "Visual Studio 12 2013 Win64 ..

采纳答案by Florian

You have to set the compiler environment accordingly before calling Ninjageneration. If you have Visual Studio 2013 installed at the standard installation path you call:

在调用Ninja生成之前,您必须相应地设置编译器环境。如果您在调用的标准安装路径中安装了 Visual Studio 2013:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64
cmake.exe -G "Ninja" ..


Edit: Thanks for the hint from @Antwane: "Or simply run CMake command from a Microsoft Visual Studio Command Prompt (x64). A shortcut to this prompt is located in Start Menu".

编辑:感谢@Antwane 的提示:“或者只需从Microsoft Visual Studio Command Prompt (x64).运行 CMake 命令。此提示的快捷方式位于开始菜单中”。

The naming varies over the Visual Studio versions:

命名因 Visual Studio 版本而异:

enter image description here

在此处输入图片说明



When I then look into the generated CMakeCache.txtfile I see:

当我查看生成的CMakeCache.txt文件时,我看到:

...
//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe
...
//Flags used by the linker.
CMAKE_EXE_LINKER_FLAGS:STRING= /machine:x64
...
//Path to a program.
CMAKE_LINKER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe
...

回答by techmancer75

When I tried to run cmake on command line in Windows, trying to use Ninja and targetting the Visual Studio 14.0 compiler (2015), it kept picking up on other installed compilers (in my case gcc) instead.

当我尝试在 Windows 的命令行上运行 cmake,尝试使用 Ninja 并以 Visual Studio 14.0 编译器(2015)为目标时,它一直选择其他已安装的编译器(在我的情况下为 gcc)。

The following command line worked:

以下命令行有效:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DMSVC_TOOLSET_VERSION=140 ..