There are no notfications.

Software build environment setup (Visual Studio 2010)

Software build environment setup (Visual Studio 2010)
Author: Stefán Örvar Sigmundsson
Initial publication:
Last updated:
Written in: English (United Kingdom)

Microsoft Visual Studio 2010 comes with a number of tools referred to as command prompts. Their purpose is to run compilers, linkers and other programs used in software development targeting the Microsoft Windows operating system as well as .NET Framework. These tools have been a source of confusion for some developers as the terminology used is ambiguous and makes differentiating between them difficult. This article is written with the assumption that Visual Studio 2010 Professional is being run on an x86-64 computer under WOW64, but it may apply equally to other versions, editions and architectures as well.

Terminology

The following terminology must be clearly understood in order to select the appropriate software build environment.

Data sizes

Computers process data in 32-bit or 64-bit units. Support for 16-bit units is still common but undesirable and archaic. Note that some CPUs may be backward compatible, therefore 64-bit computers may process 32-bit and 16-bit data and 32-bit computers may process 16-bit data.

Instruction sets

Source code is compiled into instructions that the computer understands. Many instruction sets exist but few are prevalent. The instruction set and CPU design are together called architecture. The latest version of Microsoft Windows runs on 3 architectures. Note that Microsoft may not always use the official architecture names for its products.

Architecture comparison
Name Data size Microsoft Windows Also known as
IA-32 32-bit XP, Vista, 7 i386, x86
IA-64 64-bit XP Itanium
x86-64 64-bit XP, Vista, 7 x64, AMD64

Development tools

Microsoft offers two flavours of tools called native tools and cross tools. Native tools output for the same architectures as they are being run on and cross tools output for different architectures than those which they are being run on. An example of input could be source code and an example of output could be a binary.

Native/Cross tools comparison
Input architecture Output architecture Tool
IA-32 IA-32 Native
Not IA-32 IA-32 Cross
x86-64 x86-64 Native
Not x86-64 x86-64 Cross

Background

The Microsoft Windows operating system possesses a command-line interpreter called Command Prompt (cmd.exe). It is important to note that the tools provided by Visual Studio 2010 are not actual command-line interpreters but simply shortcuts to Command Prompt. These shortcuts start Command Prompt with pre-defined arguments. The arguments passed to the Command Prompt instance can be seen by right-clicking the shortcuts and selecting Properties. The Target textbox contains the instantiation of Command Prompt (%comspec%) and the arguments passed to it.

The Command Prompt executed by the shortcuts gets passed a batch file (vcvarsall.bat) as an argument and another argument intended for the batch file itself. The purpose of the batch file is to set the necessary environment variables for the Command Prompt session. The only difference between the shortcuts is the argument that gets passed to the batch file. The argument corresponds roughly to the name of the shortcut.

One of the shortcuts is different in that the batch file it runs is called VsDevCmd.bat and it takes no arguments. The environment it sets up is intended for development of software targeting .NET Framework.

Command Prompt environment setup comparison
Shortcut Batch file Batch argument Usage
Visual Studio Command Prompt (2010) VsDevCmd.bat None .NET Framework software development
Visual Studio x64 Cross Tools Command Prompt (2010) vcvarsall.bat x86_amd64 Microsoft Windows software development
Visual Studio x64 Win64 Command Prompt (2010) amd64

Visual C++ toolset

The Visual C++ toolset is used for software development in both C and C++. It is contained in the Windows Software Development Kit (SDK) which Microsoft provides free-of-charge.

All of the environments can be automatically accessed by creating shortcuts to them as Visual Studio 2010 does or manually by executing the batch file with the relevant argument in Command Prompt. The following is generic code to set up an environment:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" architecture

The placeholder architecture must be replaced with a valid argument referring to the input/output architecture.

Architecture environment comparison
Input architecture Output architecture Argument Shortcut
IA-32, x86-64 (WOW64) IA-32 x86 None
IA-32, x86-64 (WOW64) IA-64 x86_ia64 None
IA-32, x86-64 (WOW64) x86-64 x86_amd64 Visual Studio x64 Cross Tools Command Prompt (2010)
x86-64 IA-32 None* None
x86-64 IA-64 None* None
x86-64 x86-64 amd64 Visual Studio x64 Win64 Command Prompt (2010)

* Use x86-64 (WOW64).

.NET Framework toolset

Setting up the software build environment for .NET Framework software development is straightforward. Since source code is translated into an intermediate assembly language (called Common Intermediate Language) as opposed to a platform-specific machine language, the compiled output can run on any architecture for which there is an implementation of .NET Framework.

Common Language Runtime (CLR) is the virtual-machine which runs assemblies developed for .NET Framework. Developers can choose to target CLRs running on specific architectures when compiling their source code. This can be necessary when certain components of an assembly rely on other components which are only available on a specific platform. In this context, a platform is a combination of architecture and operating system.

The /platform compiler option is used to specifies which version of the CLR can run the particular assembly being compiled. If specified, the option can take a single argument to indicate whether the software being compiled should prefer to run in 32-bit mode on a 64-bit architecture or whether the software being compiled should only run on a particular platform.

Platform argument comparison
Argument 32-bit architecture 64-bit architecture Note
anycpu execute if available execute if available This argument is the default when the option is not specified.
Itanium fails execute if available Itanium is a 64-bit architecture. Windows XP was Microsoft's last OS to support Itanium.
x64 fails execute if available IA-32 can not run 64-bit software.
x86 execute if available execute in 32-bit mode (WOW64) x86-64 can run 32-bit software using WOW64.

See also

External links