gcc -g option flag


gcc -g option flag

gcc -g generates debug information to be used by GDB debugger.


option description
-g0 no debug information
-g1 minimal debug information
-g default debug information
-g3 maximal debug information



$ gcc -glevel [options] [source files] [object files] [-o output file]



Write source file myfile.c:

// myfile.c
#include <stdio.h>
void main()
    printf("Program run!!\n");


Build myfile.c on terminal and run gdb to debug:

$ gcc -g myfile.c -o myfile
$ gdb myfile
(gdb) run
Starting program: /home/ubuntu/myfile
Program run!!
Program exited with code 012.
(gdb) quit


See also

© 2017 CalculatorX. All rights reserved.