views:

968

answers:

2

How do I add c library to Xcode Cocoa project?

Or what is the best option, I don't want to copy them into Cocoa project directory.

I have a C project called a which compiles into library a.dylib and header file a.h, the project is located in it's own directory.

I want to use this library from my objective-c application in Xcode.

How do I add the header file and library to my Xcode project?

I can drag the a.dylib into other frameworks but what do I do with a.h?

+1  A: 

You can drag them both the .a and .h files to Xcode, but make sure to not check the "Copy items to project folder". As for referencing the header file, you'll need to put it in a place where you can add a path to it in your #include/#import statements. Is there a reason you don't want to copy the header to your project file?

Ben Gottlieb
the reason for not copying it is that it is a separate project and i want to point to it, but might include it later on as it might be easier to manage, thanks
stefanB
Do you not want to copy the SOURCE, or the LIBRARY itself? To make #importing easier, I would copy the header file.
Ben Gottlieb
Preferably I would not copy either. I generally leave projects separate and only include the them in the path, this is for c/c++ projects using makefiles. I'm figuring out the best way for Cocoa and C libraries.
stefanB
+2  A: 

I figured it out.

I point to location of project a deployment directory (headers) to Search Path in project settings either:

  • as Header Search Paths, if used as <a/a.h>
  • or into User Header Search Paths, if used as "a/a.h"

As for library I just drag it to Xcode project and set it to refer to library instead of copy.

stefanB