Search code examples
eclipseeclipse-cdt

It seems not possible to include in my project, a path to a folder, that has been imported as a linked resource in my project


I have in my workspace two folders:

  1. foo
  2. bar

After opening my project foo in Eclipse, I navigated to the src folder (or inc folder - it makes no difference) in my project and then from the file menu, I selected import and then Existing Filesystem and then gave the path to bar, and selected the option to Create links in workspace.

(This would, in that dialogue, automatically check the two sub-options: "Create virtual folders" and "Create link locations relative to" PROJECT_LOC/WORKSPACE_LOC/etc. Maybe this is a moot point.)

Now, of course, I need to include the headers from the linked resource bar into my project foo somehow.

So, I click the properties of my project. And under C/C++ General, in the Paths and Symbols tab, I add the path (as a workspace path) to the linked resource bar under included directories.

I tried both "/bar" (which is where bar is actually present in the workspace),

OR,

"/${ProjName}/src/bar" (which is where bar is added to the project as a linked resource),

and in both cases, the header files from the linked resource cannot be found.

BUT, if I instead, in this project properties window, included an absolute path to the linked resource bar, e.g. /opt/workspace/bar, then the header files can be found.

This seems like a bug in eclipse, as linked below. I couldn't find if there were any fixes ever implemented for this issue.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=72940 https://bugs.eclipse.org/bugs/show_bug.cgi?id=122945


Solution

  • The problem you are facing is how the linked folders are being represented in your project (virtual vs. non-virtual) and how the -I argument is being resolved.

    The Import filesystem wizard does a very different thing when choosing Create virtual folders or not.

    Create virtual folders checked.

    In this case all the intermediary folders are virtual, i.e. they don't correspond to the folders on the file system. You can see this in a few places:

    1. The icon overlay is a blank square:

    enter image description here

    1. Adding a file to that directory on the file system will not make the file appear in the IDE. This is because the individual files are linked, not their containing folders.
    2. You can see this in the project properties like this:

    enter image description here

    Effect These folders are virtual, they don't correspond to anything actually on disk, so there is no equivalent at build time to pass to GCC, so they are omitted.

    Create virtual folders unchecked.

    In this case the link is to just the root element. You can see this in a few place:

    1. The icon overlay is a shortcut type arrow:

    enter image description here

    1. Adding a file to that directory on the file system will make the file appear in the IDE.
    2. You can see this in the project properties like this:

    enter image description here

    Effect These folders are linked, so they correspond to something on disk, therefore at build time they are passed through.

    Final Complication

    The last complication is that "/${ProjName}/src/bar/inc" is not the correct way to refer to the path. You are constructing arguments for GCC here, so you have to resolve to from the workspace representation of the location to the location on disk. Therefore, surround the whole thing with the workspace_loc variable "${workspace_loc:/${ProjName}/src/bar/inc}"

    "/${ProjName}/src/bar" -> /foo/src/bar/inc
    "${workspace_loc:/${ProjName}/src/bar/inc}" -> /tmp/so/git/bar/inc
    

    Full Example on GitHub

    I have added a full example on github and I left the generated Makefiles checked in for your reference. My git root was /tmp/so/git when looking at the Makefiles.