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 ~