GCC compiler

xiaoxiao2021-03-06  18

Source: http://www.hackerxfiles.net/ First check if the GCC is installed on your machine, using the command: You can check it with RPM -Q GCC. If not installed, please check and install the following RPM Libbinutils Binutils make glibc-debbinutils binutils make glibc-debcc-cpp GCC to see the following example: Test.c # include main () {char * str = "i like Linux ! I advice "; Printf ("% s ", str); exit (0);} Compile with GCC. Enter GCC -C Test.c to get the target file Test.-c command indicates compiling and assemble the file. But not connected. If you add GCC -O ../bin/test Test.o, you will get a executable named Test. In fact, these two can't be accomplished, gcc ../bin/test test.c. If the program has no error to save the executable. Maybe you will feel that the command-based compiler is not in the integrated development environment such as VC, it is indeed that the GCC interface should be improved, but you will feel it once you are skilled. The efficiency of GCC is so high. You can tell you that the powerful C / C integrated development environment KDevelope and VC are as strong as Linux, using the GCC compiler. The GNU C compiler, GCC is a powerful ANSI C compiler, you will operate a C compiler under other operating systems, you can quickly master GCC, I also learned GCC.1, using GCC, The GCC is based on command line, usually following some options and file names when used. The basic usage of GCC is as follows: GCC [Options] [filenames] command line options Formula will execute each of the files on the command line. 2, the common option for GCC Compile option: GCC has more than 100 compilation options available. Specific can use the command Man GCC to view the optimization option: When compiling C / C code with GCC, it will try to complete compilation with the least amount of time and easy to debug. Easy to debug means that the compiled code has the same execution order with the source code, and the compiled code is not optimized. There are a lot of ideas to tell GCC to generate smaller and faster executables on the basis of consuming more compile time and sacrificial pruning commissioning. The most typical in these options is -O and -O2. The -o option tells the GCC to optimize the source code. -O2 option tells GCC to generate as small and as fast as possible as possible. There are also some very special options that can be viewed through the Man GCC. Debug and parsing options: GCC supports several commissioning profiling options. The most commonly used -g and -pg.-g options in these options tell GCC to generate debugging information that can be used by GNU debuggers (such as GDB) to debug users. -pg option tells GCC to add additional code in the user's program, execute, generate the analysis information of GPROF to display the time consumption of the program. 3. Use GDB to use: Enter GDB in the command line and press Enter to run GDB. After starting GDB, you can set a lot of options on the command line, or you can run GDB: GDB FileName When you run GDB this way, you can directly specify the program you want to debug. In the command line, get GDB -H to get a simple list of options for GDB. Compile the code for debug, in order to make GDB work, you must make the program contain debug information, debug information contains the type of each variable in the program, and the address map in the executable file and the line number of the source code. GDB uses this information to associate the source code and the machine code.

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

New Post(0)