C语言 如何在命令行中使用 Visual Studio 编译 x64 代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2548138/
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
How to compile x64 code with Visual Studio in command line?
提问by bastibe
I want to compile a simple hello-world-style program using the Windows command line.
我想使用 Windows 命令行编译一个简单的 hello-world 风格的程序。
cl file_name.c
is easy enough. Now I want to do the same thing in 64 Bit. What should I do?
很容易。现在我想在 64 位中做同样的事情。我该怎么办?
回答by JaredPar
You need to use a version of the cl.exe compiler which emits x64 code. Which one depends a bit on your setup.
您需要使用发出 x64 代码的 cl.exe 编译器版本。哪一个取决于您的设置。
Let's consider the case you're on a 64 bit machine. For this you'll need to use the compiler which lives at
让我们考虑一下您在 64 位机器上的情况。为此,您需要使用位于
c:\Program Files (x86)\Microsoft visual Studio 10.0\VC\bin\amd64\cl.exe
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl.exe
If you're on a 32 bit machine you'll need to use the cross compiler located at
如果您使用的是 32 位机器,则需要使用位于以下位置的交叉编译器
c:\Program Files\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\cl.exe
c:\Program Files\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\cl.exe
回答by Kyle Alons
Run cl from a Visual Studio x64 Command Prompt.
从 Visual Studio x64 命令提示符运行 cl。
回答by Gabriel Cuvillier
You can also use the batch file "Vcvarsall.bat" (By default, the full path for this file is C:\Program Files\Microsoft Visual Studio 8\VC\Vcvarsall.bat for VS2005).
您还可以使用批处理文件“Vcvarsall.bat”(默认情况下,此文件的完整路径为 C:\Program Files\Microsoft Visual Studio 8\VC\Vcvarsall.bat,用于 VS2005)。
If no arguments are provided, this batch file configures the necessary environment variables for using the x86 32-bit compiler. But it can be used to configure any of the 64-bit compilers, for example to use the native 64-bit compiler pass "amd64" as argument. Then just run cl.exe.
如果未提供任何参数,此批处理文件将配置使用 x86 32 位编译器所需的环境变量。但它可用于配置任何 64 位编译器,例如使用本机 64 位编译器传递“amd64”作为参数。然后运行cl.exe。
回答by Hans Passant
Kyle is right. It is just a matter of setting the PATH environment variable properly. The regular x86 compiler lives in the vc\bin subdirectory. There are two 64-bit compilers, a 32-bit compiler that generates 64-bit code in vc\bin\x86_amd64 and a 64-bit compiler that generates 64-bit code in vc\bin\amd64.
凯尔是对的。这只是正确设置 PATH 环境变量的问题。常规 x86 编译器位于 vc\bin 子目录中。有两个 64 位编译器,一个 32 位编译器在 vc\bin\x86_amd64 中生成 64 位代码,一个 64 位编译器在 vc\bin\amd64 中生成 64 位代码。
The default Visual Studio setup always uses the 32-bit compiler to generate 64-bit code.
默认的 Visual Studio 设置始终使用 32 位编译器来生成 64 位代码。
Note that the 64-bit compilers are not installed by default. You'll have to re-run setup.exe if you didn't use the custom install option. And re-run the SP1 installer.
请注意,默认情况下不安装 64 位编译器。如果您没有使用自定义安装选项,则必须重新运行 setup.exe。并重新运行 SP1 安装程序。
回答by plswork04
Run clfrom a "Visual Studio x64 Command Prompt" or something similar like "x64 Native Tools Command Prompt for VS 2017". Run where clto see the path of which "cl" you're running. Something like "x64" or "amd64" should be in the path.
运行cl从一个“的Visual Studio 64命令提示符”或类似像“64个机工具命令提示符的VS 2017年”的东西。运行where cl以查看您正在运行的“cl”的路径。路径中应该有“x64”或“amd64”之类的东西。
The start menu search can be unhelpful at times. Try typing "vs20xx" or "vs 20xx" instead of "visual studio" to find it. The name of the prompt changes over releases. If it does not say "64", then it will set up a 32 bit environment.
开始菜单搜索有时可能没有帮助。尝试输入“vs20xx”或“vs 20xx”而不是“visual studio”来找到它。提示的名称随版本而变化。如果它不说“64”,那么它将设置一个 32 位环境。
The 64 prompt tends to just call "Vcvarsall.bat" with a 64 argument, but the argument changes over time and may not be backwards compatible.
64 提示倾向于只调用带有 64 参数的“Vcvarsall.bat”,但该参数会随着时间的推移而改变,并且可能无法向后兼容。
回答by notytony
If you have code as a part of project you can use as below
如果你有代码作为项目的一部分,你可以使用如下
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" myproject.sln /Build "Release|x64"
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" myproject.sln /Build "Release|x64"
got from below link
从下面的链接得到
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ed855b9d-55ef-49f1-bf27-f20a79be687e
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ed855b9d-55ef-49f1-bf27-f20a79be687e
回答by Andrew O'Reilly
As others have mentioned the answer depends on whether you are using a native x64 compiler or the cross compiler. This webpage should help you http://msdn.microsoft.com/en-us/library/x4d2c09s.aspx
正如其他人所提到的,答案取决于您使用的是本机 x64 编译器还是交叉编译器。此网页应该可以帮助您http://msdn.microsoft.com/en-us/library/x4d2c09s.aspx

