Search code examples
c++xcodemacosxcode4

Xcode 4 C++ header file with relative path to another header


I'm using a library with an include structure where the .h files are all in a single directory. These .h files contains a single line, a #include directive which points to the 'real' header file in specific source folder locations. The #include path in these files is relative.

So, here's an example. The directory structure is:

/project
     /sources 
         <my .cpp files>
         <my .cpp files>
         ...
     /include
         /component
             foo1.h
             foo2.h
     /platformA/something/foo1.h
     /platformB/somethingelse/foo2.h

/include/component/foo1.h contains a single line of code: #include "../platformA/something/foo1.h"

/include/component/foo2.h contains the single line of code #include "../platformB/somethingelse/foo2.h"

In my sources, I simply have: #include "component/foo1.h"

The header search path for my project points to /include

Now, Xcode 4 is able to find component/foo1.h in /include, but it's unable to follow the relative include path within those headers and find the 'real' foo1.h in the `/platformA/something' directory, and so on.

I suspect it's because the include paths in the top-level foo1.h file is relative to its location, but Xcode might be treating it as relative to some other location (project root or something)? FWIW, Visual Studio has no problems with an identical configuration.

What can I do to remedy this?


Solution

  • From your directory structure it seems that the directories platformA and platformB are placed outside the include folder. There are two possible solutions to this:

    Solution A

    Move these to include folder.

    Solution B

    Add project/platformA and project/platformB to the directories where include files should be looked for in project settings.