2

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I realized that in my attempt to simplify I had left out a few things. I updated the example to be more real. In my sources, I would like to #include "component/foo1.h", so your suggestion of moving stuff into the include folder won't really work (it would have in my incorrectly simplified example - sorry about that).
Then you can check the second solution I have proposed.
0

Don't use relative paths. Seriously, it's implementation-defined behavior how they work, so different compilers/environments/platforms will behave differently, and in your case, Xcode is almost certainly invoking GCC or clang in some sort of "build" directory, which may or may not be a sibling to your sources directory.

It's not worth the headache.

Put platformA and platformB in include, or add another directory (say, platform-include) put them in there, and add that directory to your include path.

2 Comments

Thanks, but that's not much help sadly. I share this code across multiple platform/build systems and this isn't source I control. I'd like to try and get this to work before I make life worse for me than it already is.
@psychotik: Nevermind, that doesn't actually match what you were saying, sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.