如何在 Linux 上使用 Eclipse 调试 C++ 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/248104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Do I Use Eclipse to Debug a C++ Program on Linux?
提问by Kristopher Johnson
I don't use Eclipse as an IDE, and have no interest in doing so. However, I do like its source-level debugging.
我不使用 Eclipse 作为 IDE,也没有兴趣这样做。但是,我确实喜欢它的源代码级调试。
Is there any way I can use it to debug a C++ Linux app without going through the ritual of creating a project? (In effect, can I just use it like a frontend to gdb?)
有什么方法可以使用它来调试 C++ Linux 应用程序,而无需经历创建项目的仪式?(实际上,我可以像 gdb 的前端一样使用它吗?)
If not, what are the steps I need to follow to create a project that I can use to just debug an existing C++ program that is built using Makefiles or other tools (SCons, CMake, etc.). I don't want to be able to "develop" in Eclipse; all I need to do is debug.
如果没有,我需要遵循哪些步骤来创建一个项目,我可以使用该项目来调试使用 Makefile 或其他工具(SCons、CMake 等)构建的现有 C++ 程序。我不想在 Eclipse 中“开发”;我需要做的就是调试。
采纳答案by JesperE
Take a look at this question. Create a C/C++-project, use your project's source directory as project directory, select to use the external builder, and change "make" to whatever tool you want.
看看这个问题。创建一个 C/C++ 项目,使用项目的源目录作为项目目录,选择使用外部构建器,并将“make”更改为您想要的任何工具。
The tricky part is to get the indexer to work correctly and find all your header files.
棘手的部分是让索引器正常工作并找到所有头文件。
EDIT: CMake 2.6.x has support for generating CDT project files, which might be a more straightforward solution.
编辑:CMake 2.6.x 支持生成 CDT 项目文件,这可能是一个更直接的解决方案。
回答by EML
I don't know if this has changed in the 4+ years since the question was posted, but there's a much easier way to do this. I'm on Eclipse Luna (4.4.2).
我不知道在问题发布后的 4 年多里这是否发生了变化,但有一种更简单的方法来做到这一点。我在 Eclipse Luna (4.4.2) 上。
> eclipse&
then
然后
File
> Import
> C/C++
> C/C++ Executable
> Next
> browse to executable > Next
> choose a project name > Finish
File
> Import
> C/C++
> C/C++ Executable
> Next
> 浏览到可执行文件 > Next
> 选择一个项目名称 >Finish
No other project setup required, no source paths (which should be in the object code). Just like running gdb/insight/etc. Almost makes it worth installing Java.
不需要其他项目设置,没有源路径(应该在目标代码中)。就像运行 gdb/insight/etc 一样。几乎值得安装 Java。
回答by user5325398
Configuration for debugging in Eclipse.
在 Eclipse 中调试的配置。
In eclipse,
在日食中,
- Go to Window->preferences
- A popup will appear then select C/C++ , click on drop down arrow ,then select Debug and click on drop down arrow.
- Select Source Lookup Path and then click on Add.
- After clicking on Add, click on Path Mapping and then click on OK.
- Specify the mapping path name and then click on Add .
- In compilation path select Cygwin path (need to install) and then click ok .
- In debug option,click on source Lookup Path and select
Path Mapping:Project source and click on apply and then ok
.
- 转到窗口->首选项
- 将出现一个弹出窗口,然后选择 C/C++ ,单击下拉箭头,然后选择 Debug 并单击下拉箭头。
- 选择源查找路径,然后单击添加。
- 单击添加后,单击路径映射,然后单击确定。
- 指定映射路径名称,然后单击 Add 。
- 在编译路径中选择 Cygwin 路径(需要安装),然后点击 ok 。
- 在调试选项中,单击源查找路径并选择
Path Mapping:Project source and click on apply and then ok
。