facing probelm debugging and running the code.

Hi,

I am trying to run and debug sample test.cpp file, but I am getting error “Cannot execute binary file”.
Steps I have followed are
gcc -c test.cpp -o test -g
root@ketan-laptop:~# chmod 755 test
root@ketan-laptop:~# gdb test
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “i486-linux-gnu”.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/
Reading symbols from /home/ketan/test…done.
(gdb) br main
Breakpoint 1 at 0x13: file test.cpp, line 61.
(gdb) run
Starting program: /home/ketan/test
/bin/bash: /home/ketan/test: cannot execute binary file
/bin/bash: /home/ketan/test: Success

During startup program exited with code 1.
(gdb)

suggestions are appreciated.

thanks,
Ketan

Erm, how about including the source code for test.cpp ?? :wink:

:slight_smile: Its bit lengthy code.
Tried debugging Hello world code test1.cpp
It gives same error.

I have attached test1.cpp
Please let me know if need more info.

thanks,
Ketan

Mmm, Ok, that would make sense.

-c is “compile but do not link”, so essentially you’re trying to execute unlinked object code - which is never going to work.

try;

g++ -g test1.cpp -o test

You should find this does the trick.

:slight_smile: