GCC is the most widely used tool for compiling C and C ++ languages in Linux. Unlike C and Java, generating an executable file is divided into two parts: Compilation and connection. Let's take a brief look.
For example, to compile a Test. c Application, compile the code first. The command is as follows:
Gcc-c Test. c
We will find that a file named Test is generated in the current directory. o binary file. This file is the product of compilation, but it cannot be run directly. It must be linked with the external lib before the executable file can be generated. The command is as follows:
Gcc-o Test. o
After the execution is complete, you will find that an executable file a. out is generated in the current directory and can be run using the./a. out command.
In addition, Linux C can use gcc to compile a dynamic Runtime Library, just like a dll in Windows, which can separate static coupling between lib and the execution program and facilitate program upgrade. Yes
Gcc-shared-o a. so Test. o
After the execution, you will find that the current directory generates a dynamic Runtime Library named a. so.
Of course, you can combine the compilation and link into one, for example, through
Gcc Test. c
After the command, you can directly generate a. out, suitable for use in simple programs without external lib.