One, development tools
Compiler GCC
Debugging Tools GDB
Code Editor Vim
1. Compiling commands
gcc hello.c-o Hello # Second Hello for the newly generated executable file name
-O Specify a name for the generated executable file.
-wall Print all warnings.
-E expands all user-defined predefined # define, generating the. I suffix of the C source file.
-C generates a binary file with the suffix name. O
-G generates executable binaries that can be debugged
2. Debug commands
L List of abbreviations, starting from the first line to list the code
Break 16 sets a breakpoint in line 16th of the code
Break Func sets a breakpoint at the entrance of the function func ()
Info Break View breakpoint Information
Shortcut to R run, run the program
N Next, execute the next statement
Shorthand for P i print I, printing variable i
C continue to run the program,continue command shorthand.
BT view the function stack.
Finish Exit Function
Q Exit GDB
Second, write makefile
Suppose there are three files prog.c, code.c, code.h, and the corresponding compilation commands are
gcc -C code.c-gcc -Cprog.c-gcc prog.o code.o-o test
But once you modify a file, you need to hand over the three commands again. With makefile, just a simple make command is all done.
Makefile Write as follows
TEST:PROG.O CODE.O gcc prog.o code.o-o testprog.o:prog.c code.h gcc -C prog.c-o prog.ocode.o:code.c Co De.h gcc -C code.c-o code.oclean :rm -F *.O Test
More advanced, you can also add macros to avoid "hard-coded" occurrences in makefile.
OBJS =gcc=-Wall Test: $ (BOJS) -o test $ (CFLAGS) prog.o:prog.c code.h -C prog.c-o prog.o $ (CFLAGS) code.o:code.c code.h-C code.c-o code.o $ (CFLAGS) clean: C11>rm -F *.O Test
Add:
[email protected] represents the current goal (target)
Makefile Rules
target:target file 1 target file 2 <tab> gcc -o to create a new executable file destination file 1 target file 2
Unix/linux System Programming