To take you to the Visual studio--command-line compile A/C + + program

Source: Internet
Author: User

VS Build Tool Introduction

We all know that C + + source code to generate executable. exe programs, the process needs to be compiled, linked. You only need to choose menu build or click on F5 to compile, link and run in the VS tool, in fact the IDE helps me hide a lot of specific details.

Let me first assume that VS2010 is installed in the following directory:

C:\Program Files (x86) \microsoft Visual Studio 10.0

Open the VSDIR\vc\bin in the installation directory to see a series of executable programs. exe and batch files, which are tools that VS2010 build, compile, and link to. Take a look at some of the main tools:
Cl.exe: Compiling the program
Link.exe: Linking Programs
Lib.exe: Program to load Lib library
Nmake.exe: Tools for building and compiling with makefile

Command-line compilation program

To compile the program on the command line (instead of VS), the environment variable is first formulated. Some tutorials on the web say you can do VSDIR\vc\bin\vcvars32.bat batch processing, but I get an error when I execute this batch:

Setting environment for using Microsoft Visual Studio x86 tools.

This is another problem, I don't care, direct manual preparation of environment variables:
The environment variables, advanced system settings, properties, My computer, and the environment variables (recommended for the user's environment variables) are as follows:
Vs2010_dir:
C:\Program Files (x86) \microsoft Visual Studio 10.0
WIN_SDK:
C:\Program Files (x86) \microsoft SDKs
Path:
C:\users\administrator.dnx\bin;%vs2010_dir%\vc\bin;%vs2010_dir%\common7\ide
include:
%vs2010_dir%\vc\include;%win_sdk%windows\v7.0a\include;
Lib:
%vs2010_dir%\vc\lib;%win_sdk%\windows\v7.0a\lib;

Test

D:\CppWorkspace\CommandTest\HelloWorld.cpp:

#include <iostream>#include <stdio.h>int main(){    std::cout"This is a native C++ program."std::endl;    printf("printf: Hello World");    return0;}

Compilation Result:


To compile a C + + program on the command line

Helloworld.obj is a compiled binary file, and HelloWorld.exe is a linked executable file.

Description

In the above compilation process we only use the CL compiler command to help our final executable file HelloWorld.exe, this is because the Cl.exe program at compile time itself will call Link.exe, Lib.exe and other programs.

Common compilation options can be viewed through "cl-help"

Options function
/o1 Create Small Code
/o2 Create Quick Code
/oa Assuming no aliases
/ob Controlling inline expansion
/od Disable Optimizations
/og Using global optimization
/oi Generating intrinsic functions

A more detailed introduction to the Chinese can also refer to this blog post:
Http://www.lellansin.com/%E5%BE%AE%E8%BD%AF-cl-exe-%E7%BC%96%E8%AF%91%E5%99%A8.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permitted not for any commercial use, reproduced please indicate the source.

To take you to the Visual studio--command-line compile A/C + + program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.