How to Make Visual Studio Use the Native Amd64 Toolchain

How to make Visual Studio use the native amd64 toolchain

You need to set the environment variable "_IsNativeEnvironment" to "true" prior to starting Visual Studio 2012 IDE:

set _IsNativeEnvironment=true
start "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" your_solution.sln

For Visual Studio 2013, the name of the environment variable is different:

set PreferredToolArchitecture=x64
sbm start "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" your_solution.sln

Beware that this technique does not work if the version of the IDE does not match the version of the toolchain. That is, if you use VS2013 IDE configured to run VS2012 compiler, you are out of luck. But such combination is uncommon.

Here are some links for further information:

difference between VS12 and VS13

how to embed PreferredToolArchitecture into the project in VS13

Use native 64bit Toolset in Visual Studio 2013

VS 2013 defaults to using the 'cross-compiler' which is the 32-bit EXE version of the x64 compiler. You can set an environment variable "set PreferredToolArchitecture=x64" before you start up the VS IDE to get it to use the 64-bit native EXE version of the x64 compiler.

Note that in VS 2012 this was "set _ISNATIVEENVIRONMENT=true"

How to make Visual Studio 2012 call the native 64-bit Visual C++ compiler instead of the 32-bit x64 cross-compiler?

This answer is a bit late to the party, but frustratingly there's still no good resource directly available from Microsoft's online documentation. It turns out to be easy, even if not totally convenient.

At the command prompt, type (changing the version of VS to your needs):

> set _IsNativeEnvironment=true
> "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" YourProject.sln

The clue for this is in the file

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.targets

where it says

<SetEnv Condition="'$(_IsNativeEnvironment)' == 'true'"
Name ="PATH"
Value ="$(NativeExecutablePath)"
Prefix ="false">
<Output TaskParameter="OutputEnvironmentVariable" PropertyName="Path"/>
</SetEnv>

My project is generated by CMake, so I am usually at the command prompt for a few lines before I can open VS anyway. I have always started my CMake generators after first setting up the MSVC environment, so I honestly don't know if it's required or not, but you can optionally also do (before everything else):

> call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" amd64

and /or

> call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64\vcvars64.bat"

Here's the link to the original post on MSDN where I finally found the answer.

Use 64 bit compiler in Visual Studio

By default Visual Studio uses the 32-bit toolchain (i.e. the compiler is 32-bit and cross-compiles 64-bit executables). Visual Studio 2015 and 2017 include both 32-bit and 64-bit versions of all the compilers (x86, x64, arm, arm64).

You can opt-in to using the 64-bit toolchain on a 64-bit system by two methods:

  1. Add a environment variable on your build machine (either system-wide or from a VS Developer Command Prompt).

For example:

set PreferredToolArchitecture=x64
devenv

  1. You can edit your vcxproj files to do this as well with the <PreferredToolArchitecture>x64</PreferredToolArchitecture> element:

For example:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

I use the second method in the UWP (C++/WinRT) versions of my Direct3D Game VS Templates, and I just noticed that I should add it to my UWP (C++/CX) and Win32 versions. The Xbox One XDK automatically does this in it's platform build rules as well.

Note this question has been answered in the past: How to make Visual Studio use the native amd64 toolchain

VC compiler (Visual Studio 2015) can not link big ( 2G) static lib file

The 32-bit tools can only use 2 GB of virtual address space (although they are /LARGEADDRESSAWARE so technically on the 64-bit OS they can get 3 GB of virtual space). As such, the linker is likely just exhausting virtual address space on such a large library.

The solution is to use the x64 native tools instead of the 32-bit ones.

Either set an environment variable:

set PreferredToolArchitecture=x64

Or edit your vcxproj to add the following to your project file right after <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

<PropertyGroup>
<PreferredToolArchitecture>x64</PreferredTool‌​Architecture>
</Prope‌​rtyGroup>

See Sponsored Feature: RAM, VRAM, and More RAM: 64-Bit Gaming Is Here for the details on virtual address space limits in 32-bit vs. 64-bit apps.

When compiling x64 code, what's the difference between x86_amd64 and amd64 ?

It has nothing to do with efficiency. The native and cross-compiler will both generate the same machine code. You will however gain some benefits by running a native 64-bit compiler process on a 64-bit workstation (larger registers, larger memory space, etc...).

The native compiler will only run on an 64-bit copy of Windows, so if your workstation is 32-bit this compiler won't even run.

The cross-compiler is meant to run on x86 machines even though it will run on a 64-bit copy of Windows via WoW; however, there is no reason to do this.

The page you link says it quite well:

x64 on x86 (x64 cross-compiler)
Allows
you to create output files for x64.
This version of cl.exe runs as a
32-bit process, native on an x86
machine and under WOW64 on a 64-bit
Widows operating system.

x64 on x64
Allows you to create output
files for x64. This version of cl.exe
runs as a native process on an x64
machine.

Thanks to Brian R. Bondy for the quote formatting

How to run Code Analysis on x64 Project in Visual C++?

I was having the same issue with my 64-bit C++ projects. I discovered simply renaming/removing localespc.dll from VC\bin allowed the Code Analysis builds to succeed and still report analysis warnings. It seems if VS doesn't find this dll in the VC\bin directory then it won't add the compiler switch for /analyze:plugin but otherwise passes all the other switches required by the Code Analysis.

32 bit toolchain is used for compilation even though Visual Studio 14 2015 Win64 toolchain is enabled

When executing CMake, you must specify that you want it in the 64-bit version:

cmake -G "Visual Studio 14 2015 Win64" [...]

Otherwise, in your case, by default it does the same as

cmake -G "Visual Studio 14 2015" [...]

and configures it in 32-bit mode.



Related Topics



Leave a reply



Submit