I. Run GCC / EGCS
The most important software development tool in Linux is GCC. GCC is a GNU's C and C compiler. In fact, GCC can compile three languages: C, C and ObjectC (an object-oriented extension of C language). The C and C source programs can be compiled and connected with the GCC command.
# Demo #: Hello.c
If you have two or a few C source files, you can easily compile, connect, and generate executables using GCC. For example, suppose you have two source files main.c and factorial.c two source files, and now you have to build a program that generates a calculating order.
Listing Factorial.c
#include #include int factial (int N) {if (n <= 1) Return 1; Elsereturn Factorial (N - 1) * n;}
List main.c
#include #include int factorial (int N); int main (int Argc, char ** argv) {int N; if (argc <2) {Printf ("USAGE:% SN", Argv [0]); return - 1;} else {n = ATOI (Argv [1]); Printf ("Factorial OF% D IS% D.", N, factorial (n));} return 0;}
Use the following command to compile the generated executable and execute the program:
$ gcc -o factorial main.c factorial.c $ ./factorial 5 Factorial Of 5 IS 120.
GCC can be used simultaneously to compile C processes and C programs. In general, the C compiler is determined by the suffix name of the source file or a C program. In Linux, the suffix of the C source file is called .c, and the suffix of the C source file is .c or .cpp.
However, the GCC command can only compile C source files, and the library that cannot be automatically used automatically and C programs. Therefore, the G command is usually used to complete the compilation and connection of the C program, which automatically calls GCC implementation compilation.
Suppose we have a C source file (Hello.c):
#include void main (void) {cout << "Hello, World!" << endl;
You can call G commands as follows, Connect, and generate executables:
$ G -o hello hello.c $ ./hello hello, world!
Second. The main options for GCC / EGCS
-ansi only supports ANSI standard C syntax. This option will prohibit certain features of GNU C, such as ASM or TYPEOF keywords.
-c only compiles and generates a target file.
-Dmacro defines the MacRo macro with a string "1".
-Dmacro = DEFN defines the MacRo macro in the string "DEFN".
-E runs only the C pre-encoder.
-g generate debugging information. The GNU debugger can take advantage of this information.
-Idirectory Specifies the additional header search path Directory.
-LDirectory Specifies the additional library search path Directory.
-Llibrary is searched for the specified library library.
-m486 performs code optimization for 486.
-o file generates a specified output file. When generating an executable file. -O0 does not optimize.
-O or -o1 optimized generating code.
-O2 is further optimized.
-O3 is further optimized, including inline functions.
-Shared generates shared target files. Usually used when building a shared library.
-STATIC prohibits the use of shared connections.
-Umacro cancels the definition of Macro macros.
-w does not generate any warning information.
-Wall generates all warning information.