Yu GE's c ++ Study Notes (1) Compilation Method

Source: Internet
Author: User

To learn C ++, you must first select the learning environment. Starting the Linux/g ++/C ++ journey with the help of an expert ~

In Linux, start with G ++. Write pseudo in the editorCodeLet him change from a file to the output on the screen display requires a compilation process, which is handed over to the G ++ compiler. This process is divided into four phases:

    • 1. Preprocessing;
    • 2. Compile;
    • 3. Assembly;
    • 4. links;

Let's take a look at helloworld, 1:

Figure 1

G ++ Compilation:

-C *. cpp: Compile the file into *. O obj.

-O *. O: Compile the OBJ file as an output file.

See Figure 2:

Figure 2

Hello world is output successfully.

Further steps:

As shown in figure 1, the include and pre-defined variables are often put in the header file in the development environment, so that we can modify the code, 3, 4:

Figure 3: header file

Macro definition:

# Ifndef: prevents multiple inclusion of C files.

# Define win32_lean_and_mean: the MFC module is not loaded in Win32.

Figure 4: CPP File

G ++ compilation, 5:

Figure 5

Compilation error. How is it going? No file is displayed, indicating that the header file is not found. There is a difference between the Linux and Windows environments and the relative path is not prepared in CPP, in this way, G ++ uses-I to specify the position of the header file during compilation. 6:

Figure 6

Successful! This article describes how to debug helloworld:

    • C ++ProgramStructure
    • C ++ compilation process
    • Usage of G ++ compilation commands

PS: Yu Ge is a C ++ beginner ~ Please give more suggestions to experts ~

 

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.