neowinston
neowinston

Reputation: 7764

How can I link a C++ library into an Objective-C program

I have a C++ Library that I'd like to link against my iPhone project. How do I do that?

Upvotes: 0

Views: 195

Answers (2)

Cliff
Cliff

Reputation: 11238

You have to be sure the library is built for iOS, specifically for the architecture you intend to deploy on. For instance, an Armv7 will not work on the simulator or on a pre-armv7 device like the 3G. If you want this approach to work flawlessly you probably should build a .a library for all architectures, (armv6/armv7 i386) then combine them into a fat library with the "lipo" command. This assumes you have access to the source, of course. There was a post here on SO regarding exactly how to build a fat library from source. After you've done this then it would be a simple matter of drag/dropping it into Xcode along with the headers.

Upvotes: 1

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29975

Just drag it in and make sure that the header files are available. That's it :) Make sure that the .a file (assuming that your library is a .a file) is listed on the build phases tab under "link binary with libraries".

Upvotes: 3

Related Questions