The process of generating s files under Linux is called "compiling". The compiler gcc in Linux will perform syntax analysis, semantic analysis and optimization on the preprocessed ".i" file to generate an assembly code file (".s" file). The execution syntax is "gcc -S filename.i - o file name.s"; then the assembler will convert the assembly code file into an intermediate object file; finally the linker ld will link the object file with the required static link library and dynamic link library to become an executable file.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
The process of compiling a C file into an executable file under Linux
Using gcc to compile a C file into an executable file can be separated It is four steps: pre-compilation, compilation, assembly, and connection.
1. Precompile (generate .i
file)
The precompiler cpp compiles the source files and related header files ( For example, the header file stdio.h in the example code is precompiled into an .i file.
Command executed: gcc -E file name.c -o file name.i
Function of precompilation:
a, process all "#include" precompilation directive
b, process all "#define" directives, delete all "#define" in the code, and expand all macro definitions
c, Process all conditional precompilation directives, such as #if #elif #else #ifdef #ifnodef #endif, etc.
d, delete all comments
e, add line numbers and file name identifiers, In order to give a prompt message when an error occurs
2, Compile (generate <span style="color: rgb(255, 0, 0);">.s</span>
file)
The compiler gcc performs syntax analysis, semantic analysis and optimization on the preprocessed files to generate assembly code files.
Executed command: gcc -S file name.i -o file name.s
##3. Assembly (generate .o file)
The assembler converts the assembly code file into an intermediate object fileCommand executed:gcc -c file name.s -o file name.o (Note: here It is lowercase -c, not uppercase -C. I stepped on the trap here and an exception occurred)
4. Link (generate executable file)
The linker ld links the target file with all required additional target files (such as static link library, dynamic link library) into an executable file Executed command:gcc file name. o -o File name
Example of compiling a c file into an executable file under Linux
1. Prepare C File
In the command line mode, enter: vim hello.c to enter the editing mode, enter the following code:#include<stdio.h> int main(void){ printf("Hello World!\n"); return 0; }
2. Compile
Compile the C file into an executable fileCommand to execute:gcc hello.c -o hello
3. Execute
Execute: ./hello
Linux Video Tutorial"
The above is the detailed content of What is the process of generating s files under linux called?. For more information, please follow other related articles on the PHP Chinese website!