See the example below: Test.c
#include
Main ()
{char * str = "i like linux! i advice you graion in the linux world";
Printf ("% S / N", 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.
GNU C compiler, GCC is a powerful ANSI C complaint, you will operate a C compiler under other operating systems, you can master GCC quickly, I also learned a GCC.
1. Use GCC, GCC is a command line, usually followed by some options and file names. 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, GCC common option
Compile options: 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
How to use: Enter GDB in the command line and press Enter to run GDB, start the GDB, you can set a lot of options on the command line, or you can run the GDB: GDB filename to run in this way When GDB, you can 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.
About the GCC's general writing so much, root more information can find help, remember to learn Linux's large weapons Man or Info command, next time you introduce the Makefile file and make commands of the larger program with C / C . Byebye, see it next time.
Write makefile files