20

I have two c++ projects in Eclipse CDT main and shared. In shared i have a header called calc.h. I want to use this header in main, so i did the following:

  • added #include "calc.h to the relevant files in main
  • In main's properties -> Project references i checked of shared

I hoped this would work, but I get a fatal error: calc.h: No such file or directory when compiling, so the project reference somehow doesn't work.

I can get it to work by manually adding shared's source folder in main's properties->C/C++ Build->Setting->GCC C++Compiler->Includes, but my i have a bad feeling that this will become cumbersome on larger projects more complex dependencies. I'll therefore hoped that Eclipse could handle this via project references.

Am I missing something or is manually the only way?

Tobber
  • 7,211
  • 8
  • 33
  • 56

2 Answers2

11

You are right, that is the way to do it!

I use Eclipse CDT on large projects, but I don't use the Eclipse compiler settings. There are some drawbacks to using the CDT compiler's settings:

  • As you said, on large projects, it is cumbersome.
  • If you want to compile your project on a platform which doesn't have Eclipse (when you deploy your application), it is not straightforward.

I use CMake to manage my Eclipse projects. When I start a new project, I do the following steps:

  1. In a terminal, create a folder for your new project.
  2. With your favorite text editor (vim, emacs, Text edit, kate, etc...) create the CMakeLists.txt file for your project. You don't have to create an exhaustive CMakeLists, just a small CMakeLists for your first files is enough.
  3. Then, ask cmake to generate the Eclipse project like this:
    cmake -G "Eclipse CDT41. Unix Makefiles"
    
  4. Open Eclipse, click on File --> Import, and choose "General/Existing project into workspace". Choose the folder created in the first step, and your project is ready to use in eclipse.

CMake is THE compiler configuration tool to manage projects... If you don't know this I encourage you to discover it.

Cheers!

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
Adrien BARRAL
  • 3,474
  • 1
  • 25
  • 37
0

How to use symlinks to include an Eclipse project within another Eclipse project (link a project to another project)

I like to just symlink (symbolically link) the other project into the current project at the file-system/Operating System level. This makes your file system think the other project's files are part of the current project's files, which makes Eclipse think the other project's files are part of the current project's files.

For example, in Linux (or I think MacOS too):

cd path/to/current_project
ln -si path/to/other_project .

(The above sym-linking is possible in Windows too, but the command would be different.)

Now, right-click the current Eclipse project in your "Project Explorer" in Eclipse, and go to "Refresh".

The folder you just symlinked into the current project from the other project will now show up. You'll see a file structure like:

current_project/other_project

...with all of the other project's files inside this current_project/other_project directory.

I do this trick all the time in Eclipse to get Eclipse to index and bring in the Arduino core source code into my current Arduino project so that I can easily Ctrl + Click and navigate all around the Arduino core for better understanding of everything as I work on my library or project.


Here's a readme I wrote where I fully document these instructions: https://github.com/ElectricRCAircraftGuy/AmboVent/blob/master/3-Software/Arduino/arduino_core/readme.md.

Inside this folder should be a symbolic link to your arduino installation folder. This way, an Eclipse project, for instance, can have full access to all of the Arduino source code to allow jumping to the core implementations of Arduino functions and definitions while exploring the code.

References:

  1. How to make symbolic links in Windows: https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

How to make the symbolic link to the core Arduino source code:

1) To create a symbolic link on Mac or Linux, the command looks like this. This will create a symbolic link folder called "arduino" right here:

ln -s "/path/to/arduino_installation_folder" arduino

Example:

cd /path/to/here
ln -s "/home/gabriel/Downloads/Install_files/Arduino/arduino-1.8.8" arduino

2) To create a symbolic link on Windows, the command looks like this:

mklink /D arduino "C:\Users\gabriel\Downloads\Install_files\Arduino\arduino-1.8.8" 

Keywords: eclipse import another project; symlink eclipse project; symlink Arduino core into project in Eclipse; eclipse link project to another project c/c++

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265