As my internship started, I came into contact with some new frameworks and basically used C ++ for background development. I have never used C ++ since I finished the course design, now I want to pick it up again. Therefore, if you have time, record your study notes. The development environment is also Linux. It is necessary to leave the graphic development environment before you leave the integrated development environment, we need to use makefile.Program. The basis for using makefile is to master the basic commands of GCC and G ++ compiler.
Both GCC and G ++ are GNU compilers. The former is mainly used to compile C Programs, while the latter is mainly used in C ++ languages. This articleArticleLet's share the most basic usage of these two compilers (suitable for beginners ).
In fact, the two compilers are almost the same in the compilation phase. If G ++ is used to compile C or C ++, GCC is also used in the compilation phase, one difference is that GCC cannot automatically link those libraries of iostream. Therefore, if you directly use GCC to compile and link a CPP file, the following error will occur:
/Tmp/cc9tqikr. O: In function '_ static_initialization_and_destruction_0 (INT, INT )':
Main. cpp :(. Text + 0 × 23): Undefined reference to 'std: ios_base: init: Init ()'
Main. cpp :(. Text + 0 × 28): Undefined reference to 'std: ios_base: init ::~ Init ()'
Now we know several phases of GCC Compilation: preprocessing, compilation, assembly, and link.
Preprocessing mainly processes include, define, and other commands. For example, if we define a macro, after the end of this stage, this macro will be replaced with a real value.
Compiling is to compile the. c file into. S. At this time, the C language is converted to the assembly language,
Assembly, as its name implies, refersCodeConverted to machine code
The link is the last step. Every. o file is linked to generate executable files. Common Link errors are generated at this stage, mainly when multiple source files exist.
Now let's use GCC as an example. If we have a source file of Main. C, a command will compile and connect it to generate an executable file.
Gcc-O exec main. c
The "-o" Command Option indicates that the executable file is generated and the parameter exec followed by the file name can be customized to keep up with the source file.
If we only want to compile the Assembly stage, we can use the-C command, for example:
Gcc-C main. c
In this way, the main. o file is generated, and then the link operation can be performed separately.
Of course, there are many commands in GCC. For example,-E is only used for preprocessing. When you need GDB debugging, add the-G parameter.
Write this today ~ This is the basis of makefie and will keep up with the use of the basic makefile tomorrow ~~