Search code examples
eclipseeclipse-cdt

Relative paths for include files in Eclipse CDT


Structure is this:

subsystem
  sub_dir
  sub_dir
  ...
  new_sub_dir_for _unit_test_which_includes_eclipse_workspace 
     Debug       <===   this, I think, being  ${workspace_loc} 
                        or is the parent directory ${workspace_loc}?
                        (since it contains .project and  .cproject)
     test_cases
     stubs
  file_1.c
  file_1.h
  file_1.c
  file_1.h
  ...
  software_under_test.c
  software_under_test.h

software_under_test.c says #include "../somefile.h", which is obviously outside of this subsystem.

When I am setting up my include path with Properties/C & C++ general/paths and symbols, I can't seem to use a relative path, only an absolute, which I do not want to do, as I want others to be able to build this project on their machines and the start of the path can vary per user.

I did try adding ${workspace_loc}../ and variations thereof, but I can't get it work.

What am I doing wrongly?


Solution

  • Are you using the variables option while browsing for location?

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

    • Variables
    • Workspace
    • File system

    Choose the Workspace option, the path will be relative to the workspace/project. Select the Variables option, you'll get to use variables such as ${WorkspaceDirPath}. You should be able to even reference environment variables.