Search code examples
ceclipseeclipse-cdt

Using Eclipse for C/C++ development without changing existing project directory structure


I have mostly used kate, vim etc to code and just pure console and gdb (rarely) to test. I want to start using eclipse, mainly for ease of looking up stuff, and hopefully (while not super important,) run the GUI debugger.

However, I don't want eclipse to touch my real project folders (it should change the code, obviously, but don't want it to create any configuration folders etc). Is that possible? I was thinking to create a workspace on a different folder, and add sources from my project path. But this seem to be complicated without any experience with eclipse when handling Makefiles etc!

Anyone has done something similar? any guidelines?


Solution

  • Yes, this is fairly straightforward. Instead of creating a standard C Project that creates and manages makefiles for you, use the "Makefile Project with Existing Code" instead.

    enter image description here

    If you don't want the .cproject, .project, etc files intermixed, create the CDT project in an empty directory and use Linked Files and Folders to pull in what you do want in the project.

    If you do try to do a Build within Eclipse it will do "make all", but if you don't have a Makefile you get this (same for clean):

    make all 
    make: *** No rule to make target `all'. Stop.
    

    What I have done is for projects that don't have a make equivalent (like CPython extension) is to write a trivial Makefile that delegates all and clean targets to my real tool.

    Once you have the project created, you will need to configure it to get all the goodness of CDT. The CDT Indexer and Scanner needs to know about your compiler settings (includes and defines really). There are two ways of delivering that information:

    1. Run a verbose build (i.e. with gcc command line arguments echoed) from within Eclipse (e.g. use trivial Makefile described above). CDT will parse that output and automatically pick up compiler options used.

    There are a number of ways that CDT can learn about what your settings are, to configure how they are picked up, head to project properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. and adjust the sources in the Providers tab:

    enter image description here

    1. In the project properties, edit the C/C++ General -> Paths and Symbols properties. You may have to do this if CDT cannot determine all your settings in Step 1 too. This is a screenshot of some of those settings:

    enter image description here