CentOS How to view the GCC version command under the current system

Source: Internet
Author: User
Tags function definition mathematical functions centos

1. GCC-V (Display the programs invoked by the compiler)

[Root@localhost/]# Gcc-v

Reading Specs From/usr/i386-glibc-2.1-linux/lib/gcc-lib/i386-glibc21-linux/egcs-2.91.66/specs

GCC version egcs-2.91.66 19990314/linux (egcs-1.1.2 release)

2. Rpm-qa|grep gcc

Rpm-qi GCC

[Root@localhost/]# rpm-qa|grep gcc

Gcc-3.2.2-5

Gcc-c++-3.2.2-5

Libgcc-3.2.2-5

compat-gcc-7.3-2.96.118

Gcc-g77-3.2.2-5

Gcc-java-3.2.2-5

Gcc-gnat-3.2.2-5

compat-gcc-c++-7.3-2.96.118

3. Gcc-dumpversion (Display The version of the compiler)

[Root@localhost/]# Gcc-dumpversion

egcs-2.91.66

*******************************************************************************************

The GCC (GNU C Compiler) under the Linux system is a powerful, performance-enabled multiplatform compiler for GNU, one of the works of the GNU representative. GCC is a super compiler that can compile executable programs on a variety of hardware platforms, and its execution efficiency is 20%~30% higher than average compiler efficiency.

The GCC compiler compiles and connects C, C + + language source, program, and target programs to executable files, and GCC generates a file named A.out if no executable name is given. In Linux systems, executables do not have a uniform suffix, and the system distinguishes executables from file properties from executable files. While GCC distinguishes the input file by suffix, let's introduce some of the Convention rules that GCC follows.

. c is the suffix of the file, C language source code files;

(a) A file with a suffix, which is a file of archives composed of the target file;

. c,.cc or. cxx is a suffix of the file, is a C + + source code file;

. h is the suffix of the file, is the program included in the header file;

. I for the suffix of the file, is already preprocessed C source code files;

. II is a suffix of the file, is already preprocessed C + + source code files;

. m is the suffix of the file, is the objective-c source code file;

. O is the suffix of the file, is the compiled object file;

. s is the suffix of the file, is the assembly language source code file;

. S is the suffix of the file, is precompiled assembly language source code files.

the execution process of GCC

Although we call GCC a C-language compiler, the process of using GCC to generate executables from C language source code files is not just a compilation process, but rather an experience of four interrelated steps: preprocessing (also known as precompilation, preprocessing), compilation (compilation), assembly (Assembly) and connections (linking).

Command GCC first invokes the CPP for preprocessing, during which the file contained (include), precompiled statements (such as macro definition define, etc.) in the source code file are parsed. It then invokes the CC1 for compilation, which generates the target file with the. o suffix based on the input file. Assembly process is for assembly language steps, called as to work, generally speaking. S-Suffix assembly language source code files and assembly,. S-suffix assembly language files have been precompiled and compiled to generate the. o suffix of the target file. When all the target files are generated, GCC invokes the LD to complete the final critical work, which is the connection. During the connection phase, all of the target files are placed in the appropriate position in the executable program, and the library functions that the program calls to are also connected to the appropriate location in their respective archives.

basic usage and options for GCC

When using the GCC compiler, we must give a series of necessary invocation parameters and file names. The GCC compiler has more than 100 invocation parameters, most of which we may not be able to use at all, and here we only describe the most basic and commonly used parameters.

GCC most basic usage is: gcc [options] [filenames]

Where options are the parameters the compiler needs, filenames gives the relevant file name.

-C, compiles only, does not connect to the executable file, the compiler simply generates the. o suffix's target file from the input. C source code file, which is typically used to compile subroutine files that do not contain the main program.

-O Output_filename, determines that the output file name is Output_filename, and that the name cannot have the same names as the source file. If this option is not given, GCC gives the default executable file a.out.

-G, to produce symbolic information necessary for the Symbol debugging tool (GNU GDB), we must add this option if we want to debug the source code.

-O, optimize the compilation of the program, the connection, with this option, the entire source code will be compiled, connected process optimization, so that the resulting executable can be more efficient execution, but the speed of compilation, connection is correspondingly slower.

-o2, better than-o optimized compilation, connectivity, of course, the entire compilation, connection process will be slower.

-idirname, adding the directory indicated by DirName to the list of program header file directories is the parameter used during the precompilation process. The header file in the C program contains two things:

A) #include

B) #include "myinc.h"

Where Class A uses angle brackets (< >), and Class B uses double quotes (""). For Class A, the preprocessor CPP searches for the appropriate file in the system preset include file directory (such as/usr/include), and for Class B, CPP searches the current directory for the header file, which is to tell the CPP if the required file is not found in the current directory. Look for it in the specified dirname directory. In programming, if we need this inclusion file to be distributed in different directories, we need to use the-I option to give the search path individually.

-ldirname, adds the directory indicated by dirname to the directory list of the program function archive file, which is the parameter used during the connection process. In a preset state, the connector LD looks for the required archive file in the system's preset path (such as/usr/lib), this option tells the connector to first look in the directory specified by-L and then go to the system preset path, and if the function inventory is in more than one directory, you need to use this option in turn. Give the appropriate storage directory.

-lname, when connected, loads a function library with the name "Libname.a" located in the System preset directory or in the directory determined by the-l option. For example,-LM represents a library of mathematical functions with the connection named "Libm.a."

Above we briefly introduce the GCC compiler's most commonly used features and key parameter options, more detailed information can be read on the Linux system online Help.

Assuming we have a C language source code file named TEST.c, the easiest way to generate an executable file is to:

GCC test.c

At this point, precompiled, compile the connection once completed, generate a system preset executable file named A.out, for a slightly more complex situation, such as multiple source code files, need to connect to the archives or other special requirements, to give the appropriate invocation option parameters. Let's look at a simple example.

The entire source code program consists of two files testmain.c and TESTSUB.C, the program uses the system-supplied math library, and the executable file you want to give is test, the compilation command can be:

GCC testmain.c testsub.c-lm-o Test

Among them,-LM represents the mathematical library LIBM.A of the connecting system.

the error types of GCC and Countermeasures

The GCC compiler cannot continue or generate the final executable if it discovers that there are errors in the source program. For ease of modification, GCC gives the error information, we must analyze and process the error information one by one, and modify the corresponding language to ensure the correct compilation of the source code connection. The error information given by GCC can be divided into four categories, we discuss the causes and countermeasures.

First Class: C syntax error

Error message: The nth line in the file source.c has a syntax error (Syntex errror). This type of error is generally a C language syntax error, you should carefully check the source code file in the nth line and the line before the program, and sometimes also need to check the file included in the header file. In some cases, a very simple syntax error, GCC will give a lot of mistakes, our main thing is to keep a clear mind, do not be intimidated by it, when necessary, refer to the basic C language textbook.

Type II: header file Error

Error message: Cannot find header file Head.h (Can not found include file head.h). This type of error is a problem with the Include header file in the source code file, possibly due to a header file name error, an error in the directory name of the specified header file, or incorrect use of double quotes and angle brackets.

Category III: Archival errors

Error message: The connector cannot find the function library that you want, for example:

LD:-lm:no such file or directory

This type of error is an error in the function library that is connected to the destination file. Possible causes are the function library name error, the specified function library directory name error, and so on, check the method is to use the Find command in a possible directory to look for the appropriate function library name, determine the name of the archive and directory and modify the program and the compiler options in the name.

Class Fourth: undefined symbols

Error message: There is an undefined symbol (Undefined symbol). This type of error occurs during the connection process, there may be two reasons: one is the user-defined function or global variable source code file, not compiled, connected, or simply not defined, which requires the user to modify the source according to the actual situation, give the global variable or function definition body The second is that undefined symbols are a standard library function, the library function is used in the source program, and the connection process is not given the name of the corresponding function library, or the directory name of the repository is problematic, then need to use the Archive Maintenance command AR Check which library function we need in the end of which function library, determine , modify the-L and-l items in the GCC connection options.

Exclude compilation, connection process errors, it should be said that this is only the simplest and most basic step in the program design, it can be said that only a start. The error in the process, but we are in the C language to describe an algorithm generated errors, it is easier to exclude. We write a program, to compile, connect through, should say just beginning, the program in the running process of the problem, is the algorithm design problems, said more than the point is the understanding of the problem and understanding is not enough, but also need more in-depth testing, debugging and modification. A program, a slightly complex program, often have to go through many times the compilation, connection and testing, modification. Below we learn the program maintenance, debugging tools and version maintenance is in the program debugging, testing process used to solve the debugging phase of the problems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.