Link to Files and Folders in Eclipse

Eclipse projects have the nice features that they can link to files and folders: so instead of having the physical file, it is just a pointer to a file. This is very cool as that way I can point to shared files, or keep files in a common place referenced from projects, and so on.

Linked Folder and File in Eclipse

Linked Folder and File in Eclipse

As with most things in Eclipse, there is not a single way how to do things. So I’m showing in this post several ways how to link to files and folders.

Creating a New Link

Select the folder/project where to create a link to a file. Use the context menu with New > File (or the menu File > New > Other > General > File):

New File

New File

That opens a dialog to create a new file. I can select which project/folder I want to use for this:

New File Dialog

New File Dialog

Next, click on ‘Advanced’, enable ‘Link to file in the file system’ and Browse to the file you want to link to:

Link to File

Link to File

This will set the link to the file:

Specified link to file

Specified link to file

As an absolute path (C:\….) is probably not really what you want, there are Eclipse Path Variables you can use:

Path Variables

Path Variables

πŸ’‘ Note that these are Eclipse PATH variables (not Eclipse BUILD variables), see “Eclipse Build Variables“.

To use the Path Variable for the link, use the ‘Extend…’ Button and then select the file, then press OK:

Extending Path Variable

Extending Path Variable

This now uses a PATH variable for that link. Note that it shows as well to which file it resolves:

Resolved path variable for linked file

Resolved path variable for linked file

Press Finish, and the link will be created. Note the small ‘arrow’ in the icon (see “Icon and Label Decorators in Eclipse“) to show a linked file:

Linked File

Linked File

Modifying a Link

If you right-click on that linked file and select ‘Properties’ of it, you can see that it is really a Linked File, with the link information, and you can change/Edit that link any time:

Linked File Properties

Linked File Properties

Linked Folder

As for link to files, its possible to create ‘link to folders’. It works the same way: select the folder, then use File > New > Folder:

Creating new Folder

Creating new Folder

  • Use default location: this creates a normal folder.
  • Virtual Folder: this does not create a physical folder, but a virtual ‘container’ where I can place links or other virtual folders. This is useful to organize links and virtual folders, without the need for a physical folder.
  • Linked Folder: like linked files, this links to a folder.

πŸ’‘ The cool thing about linked (source) folders is: when I add new files to that folder where it links to, the projects with that linked folder to it will ‘see’ the extra files too, and that way new files are automatically added to the project. I do this many times, and it is like a ‘library’ folder for me: I can add a new source file to that ‘library’ folder, and every project linking to that folder will automatically have it added. πŸ™‚

Deleting Links

Linked files and linked folders can be deleted from the project too. In that case, the destination of the link is *not* deleted, only the link:

Deleting a Link to a Folder

Deleting a Link to a Folder

Using Drag & Drop

As mentioned at the beginning: there are multiple ways to do the same thing in Eclipse. Instead using the top menu, or using the context menu, I can use drag & drop. To create links, I need to hold the CTRL key:

Drag and Drop with CTRL pressed to create a link

Drag and Drop with CTRL pressed to create a link

πŸ’‘ Notice that during the drag&drop with CTRL key pressed the icon gets a ‘+’ to show copy/linking mode.

When I drop the file: I get the usual choices how I want to create the link:

Link to files and Folders Dialog

Link to files and Folders Dialog

Drag&Drop of files and folders do not work inside Eclipse. What works as well under Windows is to drag&drop a file or folder from the Windows Explorer :-).

Summary

Links to files and folders are a cool thing in Eclipse, and they can be created with menus or even simpler with drag&drop. This is not limited to inside Eclipse: I can drag&drop from outside with the Windows Explorer and that way can link to files and folders everywhere πŸ™‚

Happy Linking πŸ™‚

26 thoughts on “Link to Files and Folders in Eclipse

  1. One of my projects is quite complex, on-going for years now, and ported to different micros and code on the PC. It seems whenever I share files like this (or by just adding a path like /stuff/common/C/xyz to the projects, over time things wind up out of sync and no longer build or work everywhere.
    I come back two years later and try to build for one of the targets and find things have diverged so much it takes ages to update and get things configured with conditional compile, etc. to work again.

    I tried using a continuous build server with CruiseControl but ran into problems getting command line build working in (the old classic) Codewarrior. Finally just gave up.

    Like

    • I have used Eclipse *path* variables for the links to make it portable as much as possible. The challenge is if absolute links are used, they easily get out of sync if projects get moved.
      That has worked fine for me. However, if the project is really huge and complex, I think the only good way to manage it is with using build scripts and make files: it is not easy to setup in the first place, but easier to manage then .project and .cproject files in Eclipse.

      Like

  2. Pingback: How to Add Existing Files to Eclipse Projects | MCU on Eclipse

  3. Hi Erich. I added a linked folder to a project and now i’d like to use the #include statement to reference those files. I don’t know if it’s the best way to do that, because only works if I put the entire path. There’s another way to do? (or a correct way?). Thank you, regards.

    Like

      • Hi Wrich, I did put my folder location to Compiler Include, Linker and event in the C++ project Path… but still have the message C5200 telling Header File Not Found… the only way I can have it found is if I put the same path set into above places in the #include directive in my code.. which is not what I want ! Can you help ?

        Etienne.

        Like

    • Let say the file is there :
      C:\Users\EVH\Documents\Projet\M2S\SOLUTIONS\HVAC\COMM15\Sources\

      my Workspace here :
      C:\Users\EVH\Documents\Projet\Ven\

      And my project is here :
      C:\Users\EVH\Documents\Projet\Ven\LRD009

      If I write “C:\Users\EVH\Documents\Projet\M2S\SOLUTIONS\HVAC\COMM15\Sources\” inside the Linker/compiler input setting AND the same path like this when the file is needed
      #include “C:\Users\EVH\Documents\Projet\M2S\SOLUTIONS\HVAC\COMM15\Sources\RS485.h”

      it works. But every other guess did not ! I tried
      #include “RS485.h” and
      #include
      do i need to set #include “../../M2S/SOLUTIONS/HVAC/COMM15/Sources/RS485.h”

      ???

      Like

  4. Hi Erich,

    I am trying to debug my code which is written for Cortex M4. I am using GNU ARM compiler and JLink GDB debugger.

    I am adding source files to my project using drag and drop. If I opt for “copy files” option during import, debugging is fine and current execution (Program counter) is getting mapped to code in source files properly.

    But if I opt for “Link to files” option during import, during debugging current execution (PC) is not getting mapped to source files i.e., I am seeing “No source available for 0x0” as depicted here https://imgur.com/a/ww64L

    Can you help me to overcome this.

    Like

    • I think this is not related to linked files, but due a small glitch in the GDB. Can you do an assembly step (see https://mcuoneclipse.com/2012/10/27/assembly-instruction-stepping/)? I think then the source file will show up.
      It shows “no source file for 0x0” because at the time the source view was looking for the source, the CPU had a program counter of zero, and there is no source at address zero (there is the reset vector at this address).

      Like

        • And I think you might have disabled debugging information. Check your project settings (C/C++ Build > Settings > Tool Settings > Debugging > Debug level) that it is using -g3 (maximum)

          Like

        • I am actually making use of a sample project from http://gnuarmeclipse.github.io/tutorials/hello-arm/

          Then I remove hello arm source files from project, then add my own source files and an .elf file generated externally ( i.e., not build by eclipse project environment)

          Then I do necessary changes in Debug configurations like ‘Disable auto build’, specifying .elf path in ‘Load symbols’, ‘Load executable’ etc

          Things work fine i.e., source files get mapped while debugging only if I add it by ‘copy files’ option. Keeping every thing same but just adding source files by ‘Link to files’ option, source files don’t get mapped. The reason I want ‘Link to files’ options is to avoid unnecessary copying of files in the eclipse project folder.

          So I think, the steps you suggested do not make any difference.

          Anyway I have tried to rebuild it, it did not help.

          (Note: I am using debug settings as in http://gnuarmeclipse.github.io/debug/jlink/)

          Like

        • Hi Erich,

          Actually I am making use of sample from from gnuarmeclipse.github.io/tutorials/hello-arm/

          I build above project once then I remove hello arm related source files and add my own source files. I also add an .elf file which is generated from command line using GCC ARM compiler.

          I am following Debug configuration as in http://gnuarmeclipse.github.io/debug/jlink/. Then I do necessary changes in Debug configuration like “Disable auto build”, specifying my own .elf file path in “Load symbols”, “Load executable” etc.

          Things work fine (i.e., source files get mapped during debugging) if I add source file by “copy files” option. But it does not work if I add source files by “Link to files” option.

          So I think suggestions made by you for rebuilding and debugging level setting do not make any difference.

          Anyways I tried to rebuild the project. It did not help.

          Like

        • Here is what happens: the target stops, the debugger gets the current program counter. Based on the program counter, it knows which object file it is, and uses that information to get the source file. The source file (and path) is present in the .elf file (debug information). You can see the paths to the files if you use the ‘Executables’ view in Eclipse: can you check the information for your .elf file with this view if it makes sense where the source files are?

          Like

        • Erich,

          I was creating eclipse project in C drive (default work space location) and my source files were in D drive. Today I created eclipse project in D drive itself, just at the folder level where my source files project was present. Then I added all the source files through “Link to files” option. It worked!!!

          Thanks for your continuous support.

          Like

  5. Pingback: Tips for Making Copy of Eclipse CDT Projects Easier | MCU on Eclipse

  6. Pingback: SDK Project Generator for Kinetis and KSDK – Baremetal and RTOS

  7. Pingback: Transforming Eclipse Linked Projects into Standalone Projects | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.