Summary of process of compiling C + + program with command line under Windows system

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/caikehe/archive/2013/01/12/2858017.html

(1) First write the following code as shown in Notepad, and save as Hello.cpp, assuming its save path is C:\Users\Administrator\Desktop.

#include

using namespace Std;

int main ()

{

cout<< "Hello world!" <<endl;< span= "" >

return 0;

}

(2) Write a simple batch file with Notepad, the contents are as follows, choose Save as when saving the file, the file name assumes that Batch.bat,bat is the suffix of the batch file, save type selection: All files (this is especially important to note), assuming its save path is also C:\Users\ Administrator\desktop.

Set Path=d:\softwares\en_visual_studio2010_professional_x86_x16-81637\vc\bin

Set Include=d:\softwares\en_visual_studio2010_professional_x86_x16-81637\vc\include

Set Lib=d:\softwares\en_visual_studio2010_professional_x86_x16-81637\vc\lib

The first sentence of the batch file above indicates setting environment variables, which can also be passed: Computer/Properties/Advanced system settings/environment variables/user variables, D:\Softwares\en_Visual_Studio2010_Professional_x86_ X16-81637\vc\bin is placed in the value of path and remembers to be separated from the previous value by ";". This path folder is our own when loading VS2010, when the path is set to be modified according to its own installation path, including Microsoft in Windows to provide us with C/s Compiler Cl.exe Program (compiler itself is a software program, but it is used to compile other programs), of course, there is a link.exe link program, when calling CL, the system will automatically call the link program (we will see that we use the CL command to compile C + + program , links). The following two sentences represent the header and static link libraries that are included in C + +, and the static Understanding library contains the implementation part of the function corresponding to the header file, in order to not let people see the source code, it is encoded as a binary file, to view its contents need to be disassembled.

(3) through the cmd command to enter the DOS operation interface, enter the CD C:\Users\Administrator\Desktop into the CPP file and the bat batch file where Then type batch.bat for batch processing, these operations are set for me in the VS2010 integrated development environment, so we do not have the tedious operation of setting up the path when we write C + + programs, but through our own manual path setting, we will compile, link, More in-depth understanding of implementation.

(4) Type CL Hello.cpp, we will see the computer reported "Unable to start this program because the computer is missing mspdb100.dll." Try reinstalling the program to resolve this problem "the system storage, DLL file is a dynamic link library file, which is not loaded in the Cl.exe program when the file, this static link library lib file is different. This indicates that Mspdb100.dll was not found in the D:\Softwares\en_Visual_Studio2010_Professional_x86_x16-81637\VC\bin path, originally this file is in the folder D:\ Softwares\en_visual_studio2010_professional_x86_x16-81637\vc\common7\ide, we can copy this file into the Bin folder or the D:\Softwares\en_ The visual_studio2010_professional_x86_x16-81637\common7\ide is added to the batch path environment variable, or it is added to the folder where the CPP file is located, which will only cause differences in the search order.

(5) Type CL Hello.cpp again and we see in C:\Users\Administrator\ The Desktop folder gets the Hello.obj file, which is the compiled output file, but does not get executable EXE file, the DOS interface appears such error "Link:fatal Error Lnk1104:cannot Open File" Kernel32.lib ' "Such a link error, Kernel32.lib is a Windows system file, through Windows comes with the search tool, we see this file in the folder C:\Program Files\Microsoft Sdks\ Windows\v7.0a\lib, we can add it to the folder or bin file where the CPP file is located. Typing cl hello.cpp again, we found that the program was successfully compiled link, the CPP file in the folder containing more than two files: Hello.obj and Hello.exe.

(6) In the DOS interface type Hello.exe, the program is executed, the output of our expected Hello world!, at this point, under Windows simulation of the Linux command line operation, compiled C + + files are all completed.

Compiling the C + + program process summary using the command line under Windows system

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.