In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to view the gcc version commands under the current system in CentOS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to view the gcc version commands under the current system in 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
*
Gcc (GNU C Compiler) under Linux system is a multi-platform compiler with powerful function and superior performance launched by GNU, and it is one of the representative works of GNU. Gcc is a supercompiler that can compile executable programs on a variety of hardware platforms. Its execution efficiency is 20% and 30% higher than that of ordinary compilers.
The Gcc compiler can compile and link C, C++ language source programs, assembly programs, and object programs into executable files. If the executable file name is not given, gcc will generate a file called a.out. In the Linux system, executable files do not have a unified suffix, and the system distinguishes executable files from non-executable files from their attributes. While gcc distinguishes the categories of input files by suffixes, let's introduce some of the convention rules followed by gcc.
.c suffix file, C language source code file
A file with a suffix is an archive file composed of target files
Files with the suffix .C, .cc or .cxx are C++ source code files
The file with the suffix .h is the header file included in the program.
.I is a suffix file, which is a C source code file that has been preprocessed
.II is the suffix file, which is the C++ source code file that has been preprocessed.
The file with the suffix .m is the Objective-C source code file
A file with a suffix of .o is the compiled object file
The file with the suffix .s is the assembly language source code file
The file with the suffix .s is a precompiled assembly language source code file.
The execution process of Gcc
Although we call Gcc a C language compiler, the process of using gcc to generate executable files from C language source code files is not only a compilation process, but also goes through four interrelated steps: ∶ preprocessing (also known as precompilation, Preprocessing), compilation (Compilation), assembly (Assembly), and Linking.
The command gcc first calls cpp for preprocessing. In the preprocessing process, the file inclusion (include) and precompiled statements (such as macro definition define, etc.) in the source code file are analyzed. Cc1 is then called to compile, and this phase generates the target file with the suffix .o based on the input file. The assembly process is aimed at the assembly language steps and calls as to work. Generally speaking, the assembly language source code files with the suffix .s and the assembly language files with the suffix .s and the assembly language files with the suffix .s are pre-compiled and assembled to generate object files with the suffix .o. When all the target files are generated, gcc calls ld to complete the final critical work, which is the connection. In the connection phase, all the target files are arranged in the appropriate location in the executable program, and the library functions called by the program are connected to the appropriate place from their respective archives.
Basic usage and options of Gcc
When using the Gcc compiler, we must give a series of necessary call parameters and file names. The Gcc compiler has more than 100 call parameters, most of which we may not need at all. Here we will only introduce the most basic and commonly used parameters.
The most basic use of Gcc is ∶ gcc [options] [filenames]
Where options is the parameter required by the compiler, and filenames gives the relevant file name.
-c, only compiles, does not connect to become executable files, the compiler only from the input .c and other source code files to generate .o-suffixed object files, usually used to compile subroutine files that do not contain the main program.
-o output_filename, make sure that the name of the output file is output_filename, and this name cannot have the same name as the source file. If this option is not given, gcc gives the default executable file a.out.
-g to generate the necessary symbolic information for the symbolic debugging tool (GNU's gdb). To debug the source code, we must add this option.
-O, optimize the compilation and connection of the program, using this option, the whole source code will be optimized in the process of compilation and connection, so that the execution efficiency of the resulting executable file can be improved, but, the speed of compilation and connection is slower accordingly.
-O2, better than-O to optimize the compilation and connection, of course, the whole compilation and connection process will be slower.
-Idirname, which adds the directory indicated by dirname to the list of program header files, is a parameter used during precompilation. The header file in the C program contains two cases ∶
A) # include
B) # include "myinc.h"
Where class A uses angle brackets (
< >), class B uses double quotes ("). For class A, the preprocessor cpp searches for the corresponding files in the system default containing files directory (such as / usr/include), while for class B, cpp searches for header files in the current directory. The function of this option is to tell cpp that if the required files are not found in the current directory, go to the specified dirname directory to look for them. In programming, if the inclusion files we need are distributed in different directories, we need to use the-I option to give the search path one by one.
-Ldirname, which adds the directory indicated by dirname to the directory list of the program function archive file, is a parameter used in the connection process. In the preset state, the linker ld looks for the required archive files in the system's preset path (such as / usr/lib). This option tells the linker to first look for it in the directory specified by-L, and then look in the system's preset path. If the function inventory is placed in multiple directories, you need to use this option in turn to give the corresponding storage directory.
-lname, when connecting, loads a function library named "libname.a", which is located in the default directory of the system or under the directory determined by the-L option. For example,-lm means to connect to a mathematical library named "libm.a".
Above we briefly introduced the most commonly used functions and main parameter options of the gcc compiler. For more detailed information, please refer to the online help of the Linux system.
Suppose we have a C source code file named test.c. The easiest way to generate an executable file is ∶.
Gcc test.c
At this point, the precompilation and compilation connection is completed at one time, generating a system default executable file called a.out. For slightly more complex situations, such as multiple source code files, the need to connect to archives, or other special requirements, the appropriate call option parameters should be given. Let's look at a simple example.
The whole source code program consists of two files, testmain.c and testsub.c. The program uses the math library provided by the system, and the executable file you want to give is test, so the compilation command can be ∶.
Gcc testmain.c testsub.c □ lm □ o test
Where-lm means to connect to the math library libm.an of the system.
Error types and Countermeasures of Gcc
If the Gcc compiler finds an error in the source program, it cannot proceed or generate the final executable file. In order to facilitate modification, gcc gives error messages, we must analyze and process these error messages one by one, and modify the corresponding language in order to ensure the correct compilation and connection of the source code. The error messages given by gcc can generally be divided into four categories. Let's discuss the causes and countermeasures respectively.
The first type of ∶ C syntax error
Error message there is a syntax error (syntex errror) on line n in the ∶ file source.c. This type of error is usually a syntax error of the C language. You should carefully check the nth line in the source code file and the program before that line, and sometimes you need to check the header file contained in the file. In some cases, a very simple grammatical error, gcc will give a lot of mistakes, the most important thing is to keep a clear head, do not be intimidated by it, and refer to the basic teaching materials of C language if necessary.
The second type of ∶ header file error
Error message ∶ cannot find the header file head.h (Can not find include file head.h). This kind of error is a problem with the include header file in the source code file, which may be caused by the wrong header file name, the wrong directory name of the specified header file, or the incorrect use of double quotes and angle brackets.
The third type of ∶ archives error
Error message the ∶ linker cannot find the required function library, such as ∶
Ld:-lm: No such file or directory
This kind of error is an error in the function library connected to the target file, which may be caused by the wrong function library name, the wrong directory name where the specified function library resides, etc. The check method is to use the find command to find the corresponding function library name in the possible directory, determine the name of the archive library and directory, and modify the name in the program and in the compilation options.
The fourth type of ∶ undefined symbols
Error message ∶ has an undefined symbol (Undefined symbol). This kind of error occurs during the connection process, and there may be two reasons: first, the ∶ is the source code file of the function or global variable defined by the user, which is not compiled, linked, or simply not defined. This requires the user to modify the source program according to the actual situation and give the definition body of the global variable or function. Second, the undefined symbol is a standard library function, which is used in the source program, but the name of the corresponding function library has not been given in the connection process, or there is a problem with the directory name of the archive library, then we need to use the archive maintenance command ar to check which library function we need is located in the function library, and after determining, modify the-l and-L items in the gcc connection option.
To eliminate errors in the process of compilation and connection, it should be said that this is only the simplest and most basic step in programming, and it can be said that it is only the beginning. The error in this process is only the error caused by using C language to describe an algorithm, which is relatively easy to eliminate. When we write a program, until the compilation and connection is passed, it should be said that it is just the beginning. the problem in the process of running the program is that there is a problem in the design of the algorithm. to put it more mysteriously, it is not enough to understand and understand the problem. more in-depth testing, debugging and modification are needed. A program, a slightly more complex program, often has to be compiled, linked, tested and modified many times. The program maintenance, debugging tools and version maintenance we learn below are used in the process of program debugging and testing to solve the problems in the debugging phase.
At this point, I believe you have a deeper understanding of "how to view the gcc version command under the current system in CentOS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.