Eclipse / MinGW / CDT / GDB以及调试问题

时间:2013-11-08 16:40:32

标签: c++ eclipse gdb mingw eclipse-cdt

我有一些C ++代码并尝试调试它。 main.cpp中:

#include <iostream>
using namespace std;

int main() {
    graph<int> a;
    a.add(1);
    a.addEdge(1,2);
    std::vector<int> answ = a.getAdjacent(1);
    for (unsigned int i = 0; i < answ.size(); i++)
    std::cout<<answ[i]<<std::endl;
    return 0;
}

我在“图a;”上有一个断点。但是当我开始调试时,我得到:

The target endianness is set automatically (currently little endian)
No source file named C:\Users\home\workspace\graphcpp\main.cpp.
[New Thread 3552.0xdc8]

有什么问题?

2 个答案:

答案 0 :(得分:12)

当使用eclipse + cdt和gdb时,这似乎是一个相对频繁的重复出现的问题。将默认启动器从 GDB(DSF)创建流程更改为标准创建流程似乎可以在大多数时间解决问题。

您可以在偏好设置 - &gt;运行/调试 - &gt;启动 - &gt;默认启动器下找到此选项:

Default Launchers

还要确保在编译时启用了-g调试信息。

答案 1 :(得分:0)

It seems that only with adding the standard parameters to your 'main()' function is enough (I noticed that you're not using parameters in your 'main()':

check this link

I also see this problem. The folks at LinuxQuestions.org helped me make some progress... http://www.linuxquestions.org/questions/showthread.php?t=518283

It appears that gcc 4.1.0 (ie. that in SUSE 10.1, 32-bit) has an optimization where if you don't use argc and argv in the body of main() those symbols are not present in the binary (even with -g and without any special optimization turned on). The 64-bit compiler doesn't do this incidentally.

You get the "Cannot access memory at address 0x0" from the gdb command line if you simply "break main" and print argc in a program that doesn't use argc/argv (and was compiled with gcc 4.1.0). I note your example doesn't use argc/argv.

This is true for C or C++ compilation.

Eclipse is presumably confused by this error in some way when it hits the first break. I was also getting the inability to stop at further breakpoints until I added code to reference argc/argv, or re-declare main (in C++) as "int main(int, char *[])" so that Eclipse wasn't expecting those symbols.

There is still an error in the gdb output window (no symbol "new" in the current context?), but breakpoints can be set.

HTH, -nick