views:

200

answers:

5

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?

+4  A: 

Run cl from a Visual Studio x64 Command Prompt.

Kyle Alons
How do I do that? There is only one Visual Studio Command Prompt in my Start Menu. Which is what I am already using.
BastiBechtold
@Paperflyer: You probably don't have the 64-bit compilers installed, check my post.
Hans Passant
http://msdn.microsoft.com/en-us/library/x4d2c09s.aspx
Kyle Alons
I do have them installed. (Thats what the control panel sais, anyway)
BastiBechtold
+1  A: 

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

JaredPar
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.
KTC
I have a different version of VC (2008), but I found the compiler. It is still producing strange errors, but at least this problem is solved. Thanks.
BastiBechtold
A: 

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

Andrew O'Reilly
+1  A: 

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.

Gabriel Cuvillier
+1  A: 

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.

Hans Passant