gdb "During startup program exited with code 126."

gdb

Solution

A `.o` file is not a program, it is an object file that needs to be linked with libraries to produce a program. You can use `gdb` to inspect code within it, but it is not runnable (the "cannot execute binary file" message). You will need to link it to make a program. Possibly something like

g++ -o simplesearch simplesearch.o

will suffice, but without more information it's not clear if it needs more libraries than just the system C libraries and C++ runtime support, etc.

Problem

I am debugging a c++ program: ``` gdb simplesearch.o ``` Then gdb startups successfully: ``` (gdb) Reading symbols from /home/zwx/workspace/xapian/examples/simplesearch.o...done. ``` But when I tried to run: ``` (gdb) run ``` gdb reports: ``` Starting program: /home/zwx/workspace/xapian/examples/simplesearch.o /bin/bash: /home/zwx/workspace/xapian/examples/simplesearch.o: cannot execute binary file /bin/bash: /home/zwx/workspace/xapian/examples/simplesearch.o: Success During startup program exited with code 126. ``` Someone has idea?

Original source