How do I debug C++0x programs in MacPorts gcc 4.5?

后端 未结 3 1722
庸人自扰
庸人自扰 2020-12-18 00:00

I have a simple c++ program I am trying to debug, but gdb cannot find the object file for the libraries (or no debug info is available), and it does not seem able to find th

3条回答
  •  有刺的猬
    2020-12-18 01:05

    Unlike other UNIXen, on MacOS the debug info is not linked into the executable. Instead, the executable has a list of object files which were linked into it, and the debugger looks for debug info in these individual object files.

    If you remove the object files, then you can't debug.

    When you compile and link the executable in "single step", GCC does this:

    1. Create assembly file /tmp/[random-string].s
    2. Assemble it into /tmp/[random-string].o
    3. Link /tmp/[random-string].o with crt0.o, libc, etc. into mcmc executable.
    4. Remove /tmp/[random-string].o and .s

    It is that last step which prevents you from debugging.

    Solution:

    g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -c MCMC-simplex.cpp
    g++-mp-4.5 MCMC-simplex.o -lgsl -static-libstdc++ -o mcmc
    

    This will leave MCMC-simplex.o in the current directory, and will allow GDB to find debug info in it.

提交回复
热议问题