3

Newbie here, trying to add the CHDataStructures library to a calculator project I'm working on. I did as suggested in the accepted answer at Linking a static library to an iOS project in Xcode 4 and have ended up with this:

Xcode with library added

Unfortunately, I get a 'CHDataStructures.h' file not found error when I try to add the header to classes in my project (Calculator.m, for example).

Any thoughts about how I can get the CHDataStructures library to be, like the Death Star, fully operational?

EDIT

Okay, here's trying both $(SRCROOT) and the absolute path. Any thoughts?

with `$(SRCROOT)

with absolute path

Cœur
  • 37,241
  • 25
  • 195
  • 267
Joel Derfner
  • 2,207
  • 6
  • 33
  • 45

1 Answers1

14

By default, Xcode searches for headers recursively in the project's own directory. If you're using a static library, you'll need to use the lib's header files which likely reside somewhere else. There are 2 settings in an Xcode project that allow you specify additional paths to search during compilation:

User Header Search Paths

#import "SomeHeader.h"

Header Search Paths

#import <SomeHeader.h>

Depending on which style you intend to use, pick the appropriate setting, and supply the path to the header files you wish to use:

enter image description here

The paths can be recursive, relative to the project (using $(SRCROOT)/), or absolute. You could also use the derrived data directory if you have Xcode set up correctly.

Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Thank you so much! That did it. And now I can aspire to knowing enough about coding to understand what I just fixed.... – Joel Derfner Aug 03 '12 at 23:24
  • Drat. I thought I had it, but I don't quite understand what path to use. I tried `$(SRCROOT)/Users/joel/Developer/CalculatorFourthTry` [CalculatorFourthTry is the name of the file and that's the path to it] and `"$(SRCROOT)/Users/joel/Developer/CalculatorFourthTry"`, which turned into `"$(SRCROOT)/Users/joel/Developer/CalculatorFourthTry" /**`, but I still get the errors. I'm formatting something wrong, I assume? – Joel Derfner Aug 03 '12 at 23:31
  • @JoelDerfner `$(SRCROOT)` is just an environment variable for "the absolute path to the .xcodeproj file". If you use it, you would then specify the path to headers relative to the .xcodeproj file, which isn't what you're doing there. You appear to be using an absolute path, but prepending the environment variable to it. – Matt Wilding Aug 03 '12 at 23:33
  • @JoelDerfner, as a sanity check, you can start by right-clicking on the header file in question, saying "Get Info", and copy/pasting the absolute path into the setting field. – Matt Wilding Aug 03 '12 at 23:35
  • Okay, THAT did it--I added `$(SRCROOT)/` and the error went away like magic.... – Joel Derfner Aug 04 '12 at 00:09
  • AAARGH! That didn't do it. I'll add an answer and show the issues. – Joel Derfner Aug 04 '12 at 00:17
  • @JoelDerfner The second screenshot shows warnings and errors in the headers you mention. It make it look like the header paths are now correct, but the headers themselves contain errors. Are you using non-arc headers in an ARC app? – Matt Wilding Aug 04 '12 at 00:26
  • Turns out I was working with a version written for XCode 3. Somebody else had a problem with it at http://stackoverflow.com/questions/5418832/chdatastructures-framework-wont-compile-for-ios-in-xcode-4, and the answer led me to the updated version--which is now working fine! Thanks very, very much. Hope you're having a good day/evening. – Joel Derfner Aug 04 '12 at 00:41