Eclipse CDT: How to reference 3rd party includes via a Relative path

15,767

Solution 1

When adding an include file path in the CDT project (Project Properties/C/C++ General/Paths and Symbols), there are 3 buttons to browse for a location:

  • Variables...
  • Workspace...
  • File system...

If you press the Workspace... button, the path will be relative to the workspace/project. If you select the Variables... button, you'll get to incorporate variables such as ${WorkspaceDirPath}. The variables can also reference environment variables, which might be handy if you want a single install of boost to be referenced from projects that might reside anywhere on your machine.

If you incorporate variables into the path, make sure the "Is a workspace path" option is checked - otherwise the variable seems to get evaluated when you press "OK" instead of staying a variable to be evaluated at build time.

Solution 2

I got this working doing roughly what Michael Burr suggested above:

Under Project Properties/C/C++ General/Paths and Symbols, I added paths like this:

${ProjDirPath}/../boost_1_39_0

  • Alex

Solution 3

I am using Eclipse Luna and found the accepted answer to be no longer accurate. After a bit of head scratching, it seems that a couple of changes have happened in the past few years (at least, this is what happened on my system):

  • Eclipse no longer expands variables when you click "OK" if you have not ticked "Is workspace path".
  • Eclipse cannot find any paths that are relative to the workspace unless they actually refer to projects in the workspace. Any paths that cannot be found by Eclipse will not be added to the build command line with a -I or other relevant switch

For this to work, therefore, I had to enter ${ProjDirPath}/../whatever as a non workspace-relative path, and the variable is not expanded until compile time.

Solution 4

IIRC, you should be able to right click the project and go into the C/C++ general settings. From there you can add specific include directories for the project to reference. Here's a couple of links that may help...

IBM Article

Eclipse Development

Share:
15,767

Related videos on Youtube

Alex Black
Author by

Alex Black

Alex Black's blog Alex Black on LinkedIn

Updated on April 17, 2022

Comments

  • Alex Black
    Alex Black about 2 years

    I'm new to Eclipse-CDT, setting up a new project for the first time. I'm trying to reference Boost without hardcoding an absolute path.

    I've put boost in my workspace folder, e.g. /home/user/workspace/boost_1_39_0

    I was then hoping to add an include directory pointing to that folder relative to the workspace, but Eclipse won't do that, it seems to only want to point to thinks in /home/user/workspace/[MyProjectNameHere]

    Any tips? It doesn't seem to make sense to copy Boost into my project folder, because then it shows up in Eclipse and Eclipse wants to build it (sure, I could exclude it).

    • Alex
  • Alex Black
    Alex Black almost 15 years
    Thx, yes I can do that, but I guess my question is how do I do that using a relative path.
  • Alex Black
    Alex Black almost 15 years
    I updated the question to better reflect the relative path issue
  • Alex Black
    Alex Black almost 15 years
    In Visual Studio 2008 I'd just add a relative path to the project includes directories, e.g. "../boost_1_39_0"
  • Michael Burr
    Michael Burr almost 15 years
    Eclipse seems to 'resolve' the full paths if you simply type in a relative path - though checking the 'workspace relative' checkbox might fix that. Also - what do you mean about the settings being IDE-wide? For me they seem to be attached to the specific project. But note that I'm particularly knowlegable in Eclipse. I find a lot lacking in Eclipse/CDT (especially in documentation), but it's very much good enough that using it instead of a $5000 IDE for embedded development is a good choice a lot of the time.
  • Alex Black
    Alex Black almost 15 years
    There are two spots I've found to enter these settings, the one you described seems to be not project specific. "C/C++ General" has the text beside it "Enable project specific settings" which is not checked (yet) for me.
  • Michael Burr
    Michael Burr almost 15 years
    The "Project specific settings" option seems to be a panel-to-panel option. For example, the one on the "C/C++ General" panel applies only to the Documentation tool setting. As far as I can tell, the "Paths and Symbols" settings are project-specific.
  • Michael Burr
    Michael Burr over 14 years
    Update: on re-reading my comments, I note that one says, "I'm particularly knowlegable in Eclipse" - I meant exactly the opposite - I'm not particularly knowlegable in Eclipse!
  • wsd
    wsd over 14 years
    I have a similar problem, and clicking "Workspace..." and selecting the folder my so file rests in will not work - the linker responds "no such file or directory". if I copy it to /usr/lib it works at once.