简体   繁体   中英

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". 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 ).

When I run my build in debug mode, I can debug only binary data, because debuger can't seen sources in "project" directory. 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). Now open your project properties -> c++ build and select the build folder inside your project.

Now you can compile it and create a new run configuration for debugging.

Greez ZuSe

Edit:

I assume your rootfolder looks like this

cmake/

CmakeList.txt

src/

dep/

../

now you create a folder build you switch to build and run cmake cmake ../ -flags (no eclipse-project, use default gcc)

After you have done this u can import your rootfolder to eclipse cdt and select root/build as build folder. 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)

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.
  2. Try command-line GDB - it should find sources as well.
  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.

Here is how i do it, step by step. It is a simple cmake project i downloaded from github. Works like a harm. imagebam.com imagebam.com imagebam.com 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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