views:

138

answers:

1

I'm trying to link to a static library and I keep getting linker errors. I've found a few sites that post examples but I have not been able to see what I am doing wrong.

First I create a project that will link to my lib

add> existing files
find my .xcodeproj file
select "Copy items into destination groups folder"...
Select my host project as Add To Targets.

Then I add a direct dependency to my host app
expand targets
double click MyHost.app
click + under direct dependencies
select my lib

Then I set build flags

double click MyHost application icon in Groups and Files.

click the build tab

then I set the OtherLinerFlag to -ObjC
then I set Header Search Paths to my header file location for my static library.

I pass the compile stage but any classes in my static lib cause linker error:
literal-pointer@_OBJC@_cls_refs@SomeClass in MyHost.o

thanks!

+1  A: 

The final bit I was missing was simply to click and drag the imported lib to the "Link Binary With Libraries" section of my target.

expand MyLib.xcodeproj
expand targets
expand MyApp
expand "Link Binary With Libraries"

Click and drag libMyLib.a under MyLib.xcodepoj to "Link Binary With Libraries"

I made a doc that covers all of the steps here.

http://sites.google.com/site/mikescoderama/Home/using-external-static-libraries-in-objective-c-with-xcode

madmik3
How do you import the linked library into your other files? I tried lots of permutations of #import to no avail...
zekel
You need to set the search path to where you .h files are and then simply #import "My.h".
madmik3