“无来源可用于main()”在Eclipse中使用gdb调试简单的C ++时出错 [英] "No source available for main()" error when debugging simple C++ in Eclipse with gdb

查看:344
本文介绍了“无来源可用于main()”在Eclipse中使用gdb调试简单的C ++时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



程序是在Eclipse中调试一个C ++程序(最新的Helios的RC,从本身更新为最新的CDT)非常简单(从NeHe的OpenGL教程中可以看出第2课),由一个cpp文件组成,使用OpenGL和Cocoa框架,并与libSDL.a和libSDLmain.a链接。



项目的结构非常简单:源文件位于名为src /的项目的子目录中,可执行文件构建到项目的根目录。



问题是,每当我尝试添加断点并进行调试时,断点似乎完全可以打完,但没有显示源代码,而是在代码窗口中得到一个没有可用的main()错误。 / p>

编译器标志的优化设置为无,编译器和链接器都设置了调试符号标志(-g)。



Eclipse中的调试设置设置为标准spawn proge ss,调试器设置为gdb。



现在最奇怪的是,如果我尝试调试完全相同的可执行文件 - 即。与Eclipse构建的完全相同的 - 使用终端(shell)中的gdb,然后一切正常。断点被击中,源代码显示,根本没有问题。



我确定Eclipse和shell都使用相同的gdb可执行文件,而且它们是(这是/ usr / bin / gdb)。



现在我可能是错的,但这一切都向我建议,编译器和链接器不会有问题标志(因为相同的可执行文件可以从shell调试),所以大概问题必须是如何从Eclipse中调用gdb?也许当从Eclipse gdb运行时,拾取不同的配置文件,或者从shell运行时呢? (任何人都知道?)



我真的很感激任何帮助,因为它慢慢地驱使我有余波!



请让我知道,如果有其他的细节将是有用的 - Eclipse / cdt / gdb的确切版本号,精确的链接器/编译器命令行等 - 我会很乐意与他们更新这个帖子。 p>

非常感谢提前,





--- 编辑@14小时前 ---



我尝试过添加文件系统路径 (使用搜索子文件夹)选项,但没有工作。我也试图创建一个新的完全平坦的项目,但这也没有。
我甚至试图获得一个伽利略版本(eclipse-SDK-3.5.2RC4与CDT更新),但没有任何区别(除了gdb发射速度较慢)。


$ b $这个还有一件奇怪的事情我注意到:一旦我得到无源可用消息,如果我然后切换Eclipse的控制台显示gdb控制台,并且还打开详细的控制台模式,以便我可以沟通然后,我可以发出l和bt命令,并使它们成功工作,显示我的断点被击中的正确的源和堆栈。哪个更正我错了,必须意味着信息是在那里,gdb被正确调用 - 为什么Eclipse不能看到这些信息?



接近放弃Eclipse,说实话...我也很高兴地来到了这个希望。



任何额外的帮助或想法将非常感谢。



t。

解决方案

我找到答案!而且这很简单。



问题是我正在使用SDL的Release版本而不是Debug版本! (我从MacPorts的'libsdl',而我应该有'libsdl-devel'。)



所以我的通用答案是:确保你链接的libs被编译的调试标志也设置了,这并不总是足以确保你自己的代码已经设置。


I'm having trouble debugging a C++ program in Eclipse (the latest RC of Helios, updated with latest CDT from within itself) on OSX.

The program is very simple (esentially Lesson 2 from NeHe's OpenGL tutorials), consisting of one cpp file and, using OpenGL and Cocoa frameworks, and linking with libSDL.a and libSDLmain.a.

The structure of the project is very simple: the source file(s) are in a subdirectory of the project called src/ and the executable is built to the project's root directory.

The problem is that whenever I try to add breakpoints and debug it, the breakpoints seem to get hit perfectly but no source is displayed - instead I just get a "No source available for main()" error in the code window.

The compiler flags have optimisations set to none, and both the compiler and linker have the debug symbols flag set (-g).

The debugging setting in Eclipse is set to "Standard spawn progess" and the debugger is set to "gdb".

Now the strangest thing is that if I try to debug the exact same executable - ie. the exact same one that was built by Eclipse - using gdb from the Terminal (shell) then everything works fine. Breakpoints are hit, source code is displayed, no problems at all.

I've made sure that both Eclipse and the shell are using the same gdb executable, and they are (it's /usr/bin/gdb).

Now I may be wrong, but this all suggests to me that there can't be a problem with the compiler and linker flags (because the same executable is debuggable from the shell), so presumably the problem must be with how gdb is being invoked from within Eclipse? Perhaps when run from Eclipse gdb is picking up different config files or something than when it's run from the shell? (Anyone know?)

I'd really appreciate any help with this because it's slowly driving me loopy!

Please let me know if there are any other details that would be useful - exact version numbers of Eclipse/cdt/gdb, exact linker/compiler command lines, etc. - and I'll very gladly update this post with them.

Many thanks in advance,

thoughton.

--- edited @ "14 hours ago" ---

I tried the "add filesystem path" (with "search sub-folders") option, but that didn't work. I also tried creating a new completely flat project, but that didn't work either. I even tried getting a Galileo release (eclipse-SDK-3.5.2RC4 with CDT update), but that made no difference (apart from gdb being slower to launch).

And here's something else strange I noticed: once I get the "No source available" message, if I then switch Eclipse's Console to display the "gdb" console, and also turn on "Verbose console mode" so I can communicate it, I can then issue "l" and "bt" commands and have them work succesfully, showing the correct source and stack where my breakpoint was hit. Which, correct me if I'm wrong, must mean that the information is there and gdb is being invoked correctly - so why will Eclipse not see this information?

I'm getting close to giving up on Eclipse to be honest... I came to it with such high hopes, too.

Any additional help or thoughts would be hugely appreciated.

t.

解决方案

I found the answer! And it's embarrassingly simple.

The problem was that I was using the Release version of SDL instead of the Debug version! (I had 'libsdl' from MacPorts whereas I should have had 'libsdl-devel'.)

So my generic answer is: make sure the libs you're linking against were compiled with debug flags set too, it's not always enough to just make sure your own code has them set.

这篇关于“无来源可用于main()”在Eclipse中使用gdb调试简单的C ++时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆