How to build .a (Universal Static library) using existing C++ code

1.1k views Asked by At

I have a C++ code and I am able to create .so file for Android using ndk-build

Similarly, for iOS, I intend to create .a (Universal Static library) from existing C++ code.

Question is how to build .a file with existing C++ code?

1

There are 1 answers

0
Shuduo On

In Xcode (starting with either one of the template iOS Application projects (or an existing one):

  1. Create a new static library target: File -> New -> Target.... Select Framework Or Library, and then Cocoa Touch Static Library
  2. Add library source code: Drag library source code into Xcode project. In the dialog that appears, select the build target created above.
  3. Add project dependency to the library: Select Project in Project Navigation, the the iOS build target from Targets. Select the Build Phases tab, then under Target Dependencies in the window, click on the + sign. A sheet opens (choose items to add) and the library target should be at the top of the list.
  4. Include Library in iOS Target: Under Link Binary with Libraries, click +. The library (a .a file) should be at the top of the list.
  5. Link with libc++: As the step above. Select libc++ from the list.
  6. Enable Objective-C++ compilation for any source code file that needs to include the library headers by changing the extension from .m to .mm
  7. Build the iOS application target.

Xcode will have taken care of setting everything else up for you, including compiler flags and header search paths.