• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Headers in folder references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Headers in folder references


  • Subject: Re: Headers in folder references
  • From: Andreas Grosam <email@hidden>
  • Date: Mon, 30 Jul 2012 09:30:06 +0200

On 28.07.2012, at 05:34, Rick Mann wrote:

> Hi. I'm including a folder reference in my iOS project to a folder that receives some generated C headers. They don't seem to be available to the rest of my code for #import directives. Do I need to expressly add a search path to the project for that folder?

A compiler -- or better the Preprocessor -- only knowns the system paths by default.

Xcode, on the other hand, performs some "magic" which adds a few header and framework search paths to a project which are likely to be used, and it also generates a "header search map" from the header files added to a project which makes it convenient (from the perspective of the user) to include/import headers through an unqualified include/import directive from a source file anywhere in a project without the need to add paths explicitly. Beyond this, Xcode does not do any further "magic".


This convenience comes at a cost, however:

Developers not familiar with a raw C compiler (and preprocessor), but starting with Xcode or other IDEs never had to grasp thoroughly how search paths actually do work for a compiler (preprocessor). So, you should first make yourself familiar with this topic ;)

Second, if you are in doubt which header search paths are set when compiling a certain module - check the transcript for search paths options:
-I and
-iquote

You can also set option "-v" in the "Other C Flags" option build settings, which makes the compiler driver output the search paths.


Sometimes you have to set header search paths. Often time you **should** set a path, even though Xcode had set one. But in order to avoid header search paths conflicts, and also make it more clear in the sources where a header is located it is better to set a header search path.

For example, suppose you have a header file "MyHeader.h" located in
$(SRCROOT)/MyProject/Sources/MySubmodule

#import "File.h"

*might* work without any additional work, if Xcode happens to references this file and was able to create a "header map" which created the header search path and is used "automagically". Now suppose, for any reason **and for clarity** you want to include that header more explicitly:

You can add a header search path, e.g.:
$(SRCROOT)/MyProject/Sources

and then importing the header with a qualified include directive:

#import "MySubmodul/MyHeader.h"

This way, you also will likely remove any possible header conflicts with other headers named "MyHeader.h" where also a path exists in your project. And note: Xcode adds a few paths *automatically*, which increases the possibility for a header conflict.


Note that you can add "relative paths" as header search paths. The paths are relative to $(SRCROOT). So adding
MyProject/Sources/MySubmodul   is equivalent to
$(SRCROOT)/MyProject/Sources/MySubmodul

Avoid spaces in any path!


Further readings:
< http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html >








 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Headers in folder references
      • From: Rick Mann <email@hidden>
References: 
 >Headers in folder references (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Boxed expressions
  • Next by Date: Re: Headers in folder references
  • Previous by thread: Headers in folder references
  • Next by thread: Re: Headers in folder references
  • Index(es):
    • Date
    • Thread