简体   繁体   English

如何在Eclipse CDT(C ++)上调试外部.cpp文件

[英]How to debug external .cpp files on Eclipse CDT ( C++ )

I have big project in directory "project". 我在目录“项目”中有一个大项目。 I build this project using cmake into another directory "build". 我使用cmake将这个项目构建到另一个目录“ build”中。 For coding I try to use Eclipse, but when I try to import my code into Eclipse ( File->Import->C/C++->Existing Code as Makefile Project ), of course I can import only "build" directory without "project" ( because make file are in "build" and "project" is empty for Eclipse ). 为了进行编码,我尝试使用Eclipse,但是当我尝试将代码导入Eclipse(File-> Import-> C / C ++-> Existing Code as Makefile Project)时,我当然只能导入“ build”目录,而无需导入“ project” ”(因为make文件位于“ build”中,而“ project”对于Eclipse为空)。

When I run my build in debug mode, I can debug only binary data, because debuger can't seen sources in "project" directory. 在调试模式下运行构建时,由于调试器无法在“ project”目录中看到源代码,因此只能调试二进制数据。 How I can setup debuger for use sources from "project" directory? 如何设置调试器以使用“项目”目录中的源? Thanks if some one answered! 谢谢,如果有人回答!

import your Project (rootdir not build) as MakeFile Project into the Workspace (select GNU Toolschain or Linux GCC). 将您的项目(未生成rootdir)作为MakeFile项目导入到工作区中(选择GNU工具链或Linux GCC)。 Now open your project properties -> c++ build and select the build folder inside your project. 现在打开项目属性-> c ++ build并选择项目内部的build文件夹。

Now you can compile it and create a new run configuration for debugging. 现在,您可以对其进行编译并创建新的运行配置以进行调试。

Greez ZuSe 格蕾兹·祖瑟(Greez ZuSe)

Edit: 编辑:

I assume your rootfolder looks like this 我认为您的根文件夹看起来像这样

cmake/ cmake /

CmakeList.txt CmakeList.txt

src/ src /

dep/ 单位/

../ ../

now you create a folder build you switch to build and run cmake cmake ../ -flags (no eclipse-project, use default gcc) 现在您创建一个文件夹构建,切换到构建并运行cmake cmake ../ -flags(无eclipse-project,使用默认gcc)

After you have done this u can import your rootfolder to eclipse cdt and select root/build as build folder. 完成此操作后,您可以将您的根文件夹导入eclipse cdt并选择root / build作为构建文件夹。 Where is the problem? 问题出在哪里? Eclipse CDT only wants to now where the makefile is at buildtime (thats why you manually need to select the buildfolder) Eclipse CDT只希望现在在生成时位于makefile所在的位置(这就是为什么您需要手动选择buildfolder的原因)

You do not need sources in your workspace to debug the application if you built the application on your system - build directory & paths are in your executable debug information. 如果您在系统上构建了应用程序,则不需要工作空间中的源来调试应用程序-可执行调试信息中包含构建目录和路径。

  1. Make sure you pass -g both to the compiler and linker. 确保同时将-g传递给编译器和链接器。
  2. Try command-line GDB - it should find sources as well. 尝试命令行GDB-它也应该找到源。
  3. You may setup custom source mapping in the Eclipse CDT debugger when setting up the launch configuration - but I believe this is mostly for cases when sources were moved after you built the application or if you built on another system. 设置启动配置时,可以在Eclipse CDT调试器中设置自定义源映射-但我相信这主要是针对在构建应用程序后或在其他系统上构建源时移动源的情况。

Here is how i do it, step by step. 这是我一步一步地做的事情。 It is a simple cmake project i downloaded from github. 这是我从github下载的一个简单的cmake项目。 Works like a harm. 像伤害一样工作。 imagebam.com imagebam.com imagebam.com imagebam.com http://thumbnails101.imagebam.com/23645/1e5c42236445850.jpg imagebam.com http://thumbnails101.imagebam.com/23645/1e5c42236445850.jpg imagebam.com imagebam.com imagebam.com imagebam.com http://thumbnails101.imagebam.com/23645/64cb47236445860.jpg imagebam.com http://thumbnails101.imagebam.com/23645/64cb47236445860.jpg imagebam.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM