I have two source files that I'm currently compiling into one executable.
I use gcc -o ProgramName file1.c file2.c
I know gdb requires the -g
flag when being compiled but I must be placing it incorrectly. I have tried several things but nothing along the lines of:
gcc -g -o ProgramName file1.c file2.c
is working for me. When I run gdb
-> run
it says that no executable was found.
How do I compile this correctly so it will run in GDB?
The proper command is
gdb ProgramName
followed by
run
in the prompt.
Try with:
gdb -tui ProgramName
This will open the GDB with the Text User Interface , which by default will load the source code in your screen. In this way you will know if the program was loaded.
The screen will be split, with the source code in the top and the command line in the bottom, like this:
Please compile the individual source files(cxx,c) using gcc -g -c file1.c file2.c
(so on) This will generate the file1.o file2.o files (so on ...) now compile the object files into a formal executable. gcc -g -o file.exe file1.o file2.o
On similar lines for c++ g++ -g -c file1.c file2.c
g++ -g -o file.exe file1.o file2.o
Now run the gdb file.exe
For further reference: Please go through: http://www.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html#zz-1.7
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.