Xcode - how to include c library and header file to cocoa project?

46,300

Solution 1

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.

Solution 2

Here are the steps before adding a header file test.h in your project. Here is the files location root -> Library -> include -> test.h

  1. click on build settings

  2. Find User Header Search path. add your header file location here. add following value to Debug, Release and Any Architecture field. $(SRCROOT)/Library/include. Your project Root is the folder that contains your project, it conatins .xcodeproj file.

After adding path you will be able to add header in like this

# include "test.h"

Solution 3

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?

Share:
46,300
Nubzor
Author by

Nubzor

I am a c/c++/objective-c Software Developer, mostly working on linux (Mac at home), developing software products which provide real-time connectivity to financial markets. In my free time I'm trying to keep up with what's happening in objective-c/cocoa/uikit/iOS space. In the past I have built desktop GUI in Qt, before switching to Mac. Apart from c/c++/objective-c I use python for anything else unless I find better suited tool (often plain bash scripts/make/vim/awk/sed/sqlite3 are very powerful). In the past I have worked on various modules/stacks/features that shipped as part of an mobile operating system on phones worldwide for once a major US phone manufacturer.

Updated on February 27, 2020

Comments

  • Nubzor
    Nubzor about 4 years

    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?