Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 390
Alex Black Avatar asked Jul 06 '09 22:07

Alex Black


4 Answers

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.

like image 196
Michael Burr Avatar answered Oct 21 '22 15:10

Michael Burr


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
like image 21
Alex Black Avatar answered Oct 21 '22 17:10

Alex Black


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.

like image 20
wakjah Avatar answered Oct 21 '22 17:10

wakjah


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

like image 37
nathan Avatar answered Oct 21 '22 16:10

nathan