How to compile x64 code with Visual Studio in command line?
Asked Answered
W

8

34

I want to compile a simple hello-world-style program using the Windows command line.

cl file_name.c

is easy enough. Now I want to do the same thing in 64 Bit. What should I do?

Waist answered 30/3, 2010 at 19:41 Comment(0)
C
35

You need to use a version of the cl.exe compiler which emits x64 code. Which one depends a bit on your setup.

Let's consider the case you're on a 64 bit machine. For this you'll need to use the compiler which lives at

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

c:\Program Files\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\cl.exe

Cynthy answered 30/3, 2010 at 19:48 Comment(1)
Well, on x64 machines, there's 2 options. One can use either the 32-bit x64 cross compiler, or the native 64-bits compiler. Same result.Ernestoernestus
M
24

Run cl from a Visual Studio x64 Command Prompt.

Merca answered 30/3, 2010 at 19:46 Comment(3)
How do I do that? There is only one Visual Studio Command Prompt in my Start Menu. Which is what I am already using.Waist
@bastibe, Found it under Windows Start Menu --> Under "V" (do not type ha ha) --> Visual Studio (FOLDER) -> x64 Native ToolsDegradation
@Degradation thanks! I searched everywhere, but apparently windows search doesn't find it , you need to go to the folder in start directly and look for "x64 Native Tools Command Prompt for VS 2022". Why can't MS fix its search...Grider
G
9

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).

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.

Georginegeorglana answered 30/3, 2010 at 19:53 Comment(0)
A
5

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.

The default Visual Studio setup always uses the 32-bit compiler to generate 64-bit code.

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.

Aintab answered 30/3, 2010 at 19:53 Comment(1)
OK, but I get libcpmtd.lib(ios.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64', and I am unable to set linker options using /link /MACHINE:AMD64 in VS2013Barringer
S
4

Run cl from a "Visual Studio x64 Command Prompt" or something similar like "x64 Native Tools Command Prompt for VS 2017". Run where cl to see the path of which "cl" you're running. Something like "x64" or "amd64" should be in the path.

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.

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.

Synaeresis answered 9/8, 2018 at 14:46 Comment(0)
L
1

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"

got from below link

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ed855b9d-55ef-49f1-bf27-f20a79be687e

Lamia answered 9/8, 2012 at 18:23 Comment(0)
T
0

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

Tiffanietiffanle answered 30/3, 2010 at 19:52 Comment(0)
D
-1

if you type cl/? you see option /favor:<blend|AMD64|INTEL64|ATOM> where INTEL64 is x64. see further here : https://learn.microsoft.com/en-us/cpp/build/reference/favor-optimize-for-architecture-specifics?view=msvc-170

Dank answered 19/6, 2022 at 19:20 Comment(1)
This specifies the compiler optimization. It does not switch from 32-bit to 64-bit targets. When using the 32-bit compiler, adding this option results in the warning ignoring unknown option '/favor:INTEL64'.Slur

© 2022 - 2024 — McMap. All rights reserved.