XCode include paths

15,837

Solution 1

If you include the headers in files in the project then XCode will always find them without path qualification, as you've discovered. The best solution is to remove the headers from the project and specify "Library/Headers" as a header search path in your project settings. The headers won't show in your project, but they also won't be implicitly found by XCode while compiling, either; client code will have to specify the full path off of "Library/Headers" to get to the header file they want.

Solution 2

You're running up against Xcode's behaviour that it builds a flat-headermap. You can disable this by adding the build setting:

HEADERMAP_INCLUDES_FLAT_ENTRIES_FOR_TARGET_BEING_BUILT=NO

to your project settings.

Share:
15,837
Admin
Author by

Admin

Updated on June 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm having a problem getting XCode to deal with a particular file structure that I am using or that I wish to use.

    I have a set of files in the following form...

    
    Library
       Headers
          Library
             Package1
                Header1.h
                Header2.h
                HeaderN.h 
             Package2
                Header1.h
                Header2.h
                HeaderN.h 
             PackageN
                Header1.h
                Header2.h
                HeaderN.h 
       Source
          Package1
             Source1.m
             Source2.m
             SourceN.m 
          Package2
             Source1.m
             Source2.m
             SourceN.m 
          Package3
             Source1.m
             Source2.m
             SourceN.m 
    
    

    The include model I want for code outside of this library is...

    #import "Library/Package/Header.h"
    

    I want to point XCode at Library/Headers but not at the internal folders. When I add this tree to the project XCode seems to make implicit include paths to every node in the tree.

    Client code within the project but outside this tree can do this...

    #import "Header.h"
    

    instead of...

    #import "Library/Package/Header.h"
    

    I can't seem to find a way to dissallow the non-qualified form.

    Any help would be appreciated.

    Thanks, -Roman

  • Admin
    Admin over 14 years
    I see. Thats a shame when I'm authoring the library and the app at the same time. Guess I could always break it out into its own project. I tried making a library target within the same project but that doesn't change the implicit paths either.
  • jd.
    jd. over 11 years
    Roman, I have found this exact solution before, and forgotten about it until you mentioned it 3 years ago. The stackoverflow mental circle is complete :)