CC ++ compiler GCCEGCS on Linux

xiaoxiao2021-03-06  37

1. Run the most important software development tool in GCC / EGCSLinux 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 FACTORIAL (INT N)

{

IF (n <= 1)

Return 1;

Else

RETURN FACTORALEAL (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:% s N", 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!

转载请注明原文地址:https://www.9cbs.com/read-60167.html

New Post(0)