Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Visual Studio 2012 seems to always call the 32-bit version of cl.exe located at %ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\bin\x86_amd64) instead of the 64-bit one located at %ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\bin\amd64.

I tried prepending $(VCInstallDir)bin\amd64 to the beginning of the "Executable Directories" list in the VC++ Directories section of the Microsoft.Cpp.x64.user property sheet, but that doesn't work at all -- when I rebuild I get this error:

TRACKER : error TRK0002: Failed to execute command: "
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64\CL.exe"
@C:\Users\<my_profile>\AppData\Local\Temp\tmpf3d817cafe064ad28e7dd62b2cb591c3.rsp
". The operation identifier is not valid.

How can I make Visual Studio 2012 use the native 64-bit C++ compiler?

like image 799
user541686 Avatar asked Jan 07 '13 00:01

user541686


People also ask

How do I change the compiler in Visual Studio?

You can set compiler options for each project in its Visual Studio Property Pages dialog box. In the left pane, select Configuration Properties, C/C++ and then choose the compiler option category. The topic for each compiler option describes how it can be set and where it is found in the development environment.

How do I change from x86 to x64 in Visual Studio?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.

Is Visual Studio 32-bit or 64-bit?

Visual Studio 2022 on Windows is now a 64-bit application.

Which compiler does Visual Studio use for C?

Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.


1 Answers

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.

like image 111
Tanaya Avatar answered Oct 04 '22 22:10

Tanaya