views:

783

answers:

4

Hi, what is the best practice to reference 3rd party C++ components (e.g. includes, libraries) using relative paths in Eclipse-CDT?

  • I'm trying to reference Boost and Google protobuf.
  • I've put them each in a folder in my workspace, e.g. /home/user/workspace/boost_1_39_9
  • I've added a reference to that folder under build settings in the project properties, BUT eclipse won't let me specify that path as relative to the workspace folder, I have to choose it using filesystem and specify an absolute path

thanks,

  • Alex
A: 

I'm not sure about paths for CDT build settings (not at my computer) but can't you use the workspace variable? Something like: ${workspace_loc}/boost_1_39_9

Edit: OK, I did some searching and found some information on those variables, here. I think what you want is: ${project_loc:/boost_1_39_0} ?

RayOK
I tried, that, but that doesn't seem to work. 1. Eclipse won't let you create something like that, it forces you to pick ${workspace_loc}/[YourProjectName]/boost_1_39_0 2. If I enter what you suggested manually, it *appears* to work, but Eclipse can't find my includes.
Alex Black
I wasn't planning on putting boost in the project location, because then Eclipse will want to build it.
Alex Black
A: 

Eclipse variables, such as ${workspace_loc} and ${project_loc} only work for things that are actually in the runtime Eclipse workspace. When you say you put them under the workspace in the filesystem, did you actually import the files into Eclipse (using new Project; or creating a linked folder in an existing project)?

If the files exist in the filesystem but not in Eclipse itself then Eclipse will only be able to access them with absolute paths.

BTW, CDT has variables of its own: ${WorkspaceDirPath} ${ProjDirPath} ${ProjName} which expand to the particular filesystem location.

James Blackburn
A: 

I solved this problem using the Preferences->General->Workspace->Linked Resources option.

Basically you define a variable pointing to your workspace folder.

Then add to your project the third-party folder using Add folder->Advanced->Link to folder in the filesystem, and use the Variables... button to use the previously created variable to point to the third-party folder (using the Extend button).

Then you just need to add the folder to your include and library paths in the project settings.

Easy as cake... :S

pau.estalella
A: 

Just a thought.. have you tried installing boost such that the includes go under /usr/include and /usr/lib/ or /lib. Then just add those paths in your build preferences. I have had similar issue, but then we resolved it by using custom makefiles. It worked for us because we already had the custom build framework and just need to do some changes to an existing makefile and copy it over to this project.

Hardy