How to compile C/C ++ programs using Visual Studio-command line

Source: Internet
Author: User

How to compile C/C ++ programs using Visual Studio-command line
VS build tool Introduction

We all know that the C/csf-‑source code must be compiled and linked to generate executable. EXE programs. In the VS tool, you only need to select the menu Build or press F5 to compile, link, and run. In fact, IDE has helped me hide a lot of details.

First, let's assume that VS2010 is installed in the following directory:

C: Program Files (x86) Microsoft Visual Studio 10.0

OpenVSDIRVcincan see a series of executable program .exe and batch files. These are the tools used for VS2010 construction, compilation, and linking. Let's take a look at several major tools:
Cl.exe: Compile the program
Link.exe: link Program
Lib.exe: The program that loads the lib Library
Nmake.exe: a tool for building and compiling with makefile

Compile a program using the command line

To compile a program in the command line (instead of VS), you must first prepare the environment variable. Execute some online tutorialsVSDIRVCin cvars32.bat can be used for batch processing, but an error will be reported when I execute this batch:

Setting environment for using Microsoft Visual Studio 2010x86 tools.

This is another problem, so I don't care. Directly manually configure the environment variable:
Right-click my computer-> properties-> advanced system settings-> advanced-> environment variables. The values of the prepared environment variables (recommended in 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: UsersAdministrator. dnxin; % VS2010_DIR % VCin; % VS2010_DIR % Common7IDE
Include:
% VS2010_DIR % VCinclude; % WIN_SDK % Windows 7.0 AInclude;
Lib:
% VS2010_DIR % VClib; % WIN_SDK % Windows 7.0 ALib;

Test

D: CppWorkspaceCommandTestHelloWorld. cpp:

#include 
  
   #include 
   
    int main(){    std::cout << This is a native C++ program. << std::endl;    printf(printf: Hello World);    return 0;}
   
  

Compilation result:


Compile C/C ++ programs in the command line

  <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + NbGzsS8/qOsSGVsbG9Xb3JsZC5leGW + zcrHwbS907PJtcS/yda00NDOxLz + oaM8L3A + DQo8aHIgLz4NCjxoMiBpZD0 = ""> description

Program.

You can use "cl-help" to view frequently used compilation options.

Option Function
/O1 Create small code
/O2 Create quick code
/Oa Assume there is no alias
/Ob Control Inline expansion
/Od Disable Optimization
/Og Use global optimization
/Oi Generate internal functions

 

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.