Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse CDT add existing source without copying

Tags:

c++

eclipse

I have a C++ project proj1 with some source files in, however I would like to also use some of the source files I have in another project proj2. proj1 and proj2 are both subdirs of a directory my_projects. I don't want eclipse to copy the files as I want to ensure I have only one copy to edit. This is like the "add existing item" option of MS Visual Studio.

The end result I'm aiming for is to be able to create makefiles for both proj1 and proj2, zip up the two directories together and send them to coworkers so they can build the two projects themselves using make.

Is this possible in Eclipse? I've searched and haven't found the solution.

Phil

like image 821
Phil Rosenberg Avatar asked Dec 11 '12 16:12

Phil Rosenberg


People also ask

What is Eclipse CDT builder?

The CDT is Eclipse's C/C++ Development Tooling project. It is an industrial-strength C/C++ IDE that also serves as a platform for others to provide value-added tooling for C/C++ developers.


2 Answers

I looked forever for a solution to this, and I finally found it. Right click on the project and select Build Settings. Under the Build header on the left click "Settings". Then under the "Tool Settings" tab click "Directories" under the compiler header. Then click the add button at the top. If the desired files are in another project in the same workspace click the workspace button and then navigate to the exact folder where the files are. Once you have done this voila! you should be able to build the project!

like image 65
agruwell Avatar answered Sep 23 '22 23:09

agruwell


If you have proj2 open in Eclipse right click on the project and choose Import... and then select General > FileSystem and hit next. In the top window choose the directory in proj1 that contains the resources you want to link. After selecting the files you want to link in the top window hit the Advanced button to open up a submenu and select Create Links in Workspace as shown in this screenshot: enter image description here

This question addresses setting up a Makefile with relative instead of absolute paths: Getting Eclipse CDT to use relative include paths in generated Makefiles

like image 26
Ryan Maloney Avatar answered Sep 20 '22 23:09

Ryan Maloney