Required compiler options

The first step in using gdb is to compile your code with the debugging option -g. Do this by inserting one or more of the following lines in your Makefile:
   .cc.o: ; g++ -c -g $*.f
   .c.o: ; gcc -c -g $*.c
   .f.o: ; g77 -c -g $*.f
(The first is for C++ code, the second for C.) You may also use the -g option on the command line. For example,
   % g++ -g foo.cc -o foo
   % gcc -g foo.c -o foo
   % g77 -g foo.c -o foo
When you use the -g option, be sure not to call for optimization with the -O option, since the optimizer often puts compiled code in a different order from the source code. So execution will not follow the source code order, which leads to confusion.