It is pretty simple actually. Hopefully you chose to install 64-bit compilers and linkers when you installed Visual Studio 2005 (x64 Compilers and Tools component for x64 and Itanium Compilers and Tools component for Itanium during custom install), open your solution and choose Build->Configuration Manager… from the main menu to get to the Configuration Manager dialog. You can also access the Configuration Manager screen by clicking on the Solution Platforms combo box in the menu bar (that shows Win32) and then choosing Configuration Manager… from the drop down or going via Project -> <Project>Properties –>Configuration Manger.

Once you are in the Configuration Manager dialog you can add a new platform to all configurations of the project by clicking on the Platform column and choosing <New…> from the dropdown.

Adding new platform in Visual Studio Solution

Then you will get the New Project Platform dialog where you can choose x64 (aka AMD64) in the New Platform dropdown and choose to copy settings from Win32. You will perhaps have to tweak the project settings later for one reason or other but you are better off having most of the stuff like UNICODE, _UNICODE preprocessor definitions setup correctly in the new x64 configuration you are about to create.

New project platform dialog 

You can also add a new platform to the solution by clicking on the Active solution platform combo dropdown and choosing <New…> there. This leads to New Solution Platform dialog which is very similar to the previous dialog.

New Solution Platform Dialog

Once you ok this, you will see x64 configuration in your project(s)/solution. If you do not see x64 in the drop down, try running the Visual Studio installer again and make sure the 64-bit tools are installed.

If this is a C++ project, remove WIN32 from your C++ preprocessor definitions.

The x64 configuration output directory [Project Properties->Configuration Properties->General->Output Directory] is set up by default as $(SolutionDir)$(PlatformName)\$(ConfigurationName) whereas Win32 sets output directory as $(SolutionDir)\$(ConfigurationName).  $(PlatformName) is needed in 64-bit because there are two 64-bit platforms (amd64/x64 and ia64/Itanium) whereas in 32-bit we had just one (x86). If you wish, you can introduce $(PlatformName) into you Win32 configuration to keep your output directories consistent with their 64-bit counterparts. Otherwise your x64 output will be under x64\Debug or x64\Release sub-directory whereas Win32 output would be under Debug or Release.

If you want to compile for the IA64 (Itanium) platform, the process is exactly same as above. You just add platform corresponding to IA64 instead of x64.

To compile your solution via command line, you should use vcvarsall.bat <platform> to setup environment variables correctly so that tools for the target build platform are used. This batch file is in C:\Program Files\Microsoft Visual Studio 8\VC directory by default. That file looks like thus –

The batch file that is key to compiling for 64-bit

Notice all the possible platforms that can be passed to this batch file in the usage section of the file. Also note that if no platform is specified, vcvarsall.bat calls the vcvars32.bat (the batch file we all know and love from 32-bit world). On a 32-bit x86 machine, you can call vcvarsall x86_amd64 to cross-compile for x64 . Similarly to cross compile for Itanium IA64 you would call vcvarsall x86_ia64. If you are already running in amd64 and need to build binaries for x64 you would simply need to do vcvarsall amd64 or vcvarsall x64. Notice that there is no cross compilation possible for IA64 from x64/amd64.

After you execute the appropriate vcvarsall command in the command prompt, you can attempt building by typing something like “devenv <your-solution-to-build> /rebuild Debug /useenv” and devenv will automagically pick up the right compiler and linker for you.

Now good luck with those compiler and linker errors 🙂

Tagged with →  
Share →

2 Responses to Compiling 64-bit applications in Visual Studio 2005

  1. anonymous says:

    This instruction does not work. For C#, the VS2K5 DEVENV.EXE will always pickup the C# compiler from the 32bit platform
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib- /platform:x64 /errorreport:prompt /define:TRACE /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:obj\x64\Release\Interop.XYZ.dll /reference:obj\x64\Release\Interop.XYZ2.dll /debug:pdbonly /optimize+ /out:obj\x64\Release\MyFile.dll /target:library EventSystemRegistrar.cs Program.cs Properties\AssemblyInfo.cs SENSLogon.cs SensLogonInterop.cs

    warning CS1607: Assembly generation — Referenced assembly ‘System.Data.dll’ targets a different processor

    warning CS1607: Assembly generation — Referenced assembly ‘mscorlib.dll’ targets a different processor

    It basically linked the 32-bit lib to the code and the EXE will not load as 64bit process correctly.

    The only possible way, install VS2K5 on a 64bit OS, run the command-line windows for 64bit compilation, use MSBuild to build the project.

  2. Satya Das says:

    My post was based on C/C++ projects. It seems like VS 2005 does not install the 64-bit CLR unless you install on 64-bit OS, which may be what your issue is. Quote from msdn

    Visual Studio 2005 will install the 32-bit version 2.0 CLR on an x86 machine, and both the 32-bit and appropriate 64-bit version 2.0 CLR on a 64-bit Windows machine.

    You might want to look for any 64-bit directories that may have a setup that you can manually run to get the .NET 64-bit CLR bits.

Leave a Reply

Your email address will not be published. Required fields are marked *


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop us a note so we can take care of it!

Visit our friends!

A few highly recommended friends...

Set your Twitter account name in your settings to use the TwitterBar Section.