barry007
barry007

Reputation: 539

How do I use a C libary in my Objective-C iOS project?

I'm writing a program for iOS and want to use the Apache Portable Runtime and the Subversion C library in my project.

Since this is the first time I'm trying to do this I have no idea where to start.

I already made a new C/C++ library project, imported all apr.h and svn.h files in the project, set the sdk to iOS7

It compiles well and it outputs an .a file but when I import it into my project it doesn't get linked or something.

Could anybody know a tutorial or maybe a svn library for objective c? Or at least point me in a right direction.

The only results I get while googling it are:

"Objective-C should support C Libraries natively, this should be very easy"

Not so easy for me I suppose. ;)

Upvotes: 0

Views: 115

Answers (2)

aha
aha

Reputation: 4634

If you have the sourcecode of the C project, you can directly put all the source code into your project. Xcode knows how to compile C code and it will just be compiled with the rest of your project.

As mentioned by @Adam-Smith, you can directly interface with the C objects in your Objective-C code and the C objects will not be managed by ARC

Upvotes: 1

Erik Engheim
Erik Engheim

Reputation: 8512

This is how you can troubleshoot:

  1. Click your blue project icon.
  2. Select the Build phases tab in your main view.
  3. Expand "link with libraries".

Make sure your .a file is in this list. If not add it.

If you still have problems check your build logs (right most icon on left pane). The build logs contain a long list of what your compiler did. There are icons to the far right looking like 5-6 lines on top of each other. Actually the icon is hidden until you hover over it.

Clicking this will expand a compiler step and show you exactly what arguments were provided to your compiler. This will be pretty long so it might be smart to copy to an editor. But it will contain switches such as -I for including header files, -L for location of libraries etc. Check that your .a file is in fact included during compilation of the code which depends on it. Should be a -l switch I believe.

Upvotes: 1

Related Questions