Chilkat iOS — Compiling & Linking in Xcode
How to add the Chilkat iOS static library (or XCFramework) to your Xcode project and link it successfully — for Objective-C, Swift, and C / C++.
Jump to: Before you start Two approaches Add a static library Add an XCFramework Linker flags Swift Using & unlocking Memory & ARC More notes
Before you start
The download contains a separate static library for each architecture slice. Before linking, combine the slices you target into a universal static library or an XCFramework, as described on the dedicated page:
For reference, the slices in the download are:
- Device:
lib/arm64,lib/arm64e,lib/armv7,lib/armv7s - Simulator:
lib/arm64-sim(Apple Silicon),lib/x86_64(Intel)
Two ways to integrate Chilkat
Static library (.a)
Link the universal libchilkatIos.a directly. You manage the header
search path and choose the device or simulator library per build.
XCFramework
Add Chilkat.xcframework once. It bundles the device and simulator
libraries plus headers, and Xcode selects the correct binary automatically.
Both approaches still require the linker flags below. Steps for each follow.
Adding a static library (.a)
-
Add the header search path
In Build Settings → Header Search Paths, add the directory containing the Chilkat headers:
include— for Objective-C and Swift (theCko*classes)cpp_include— for C / C++ (theCk*classes)
-
Link the library
Go to Build Phases → Link Binary With Libraries, click +, then Add Other…, and select the universal
libchilkatIos.ayou built. (Xcode adds its folder to Library Search Paths automatically.) -
Add the linker flags
Add the required flags to Other Linker Flags — see Linker flags below.
-
Select the matching library for your target
Link the device library for device builds and the simulator library for simulator builds. (An XCFramework avoids having to switch.)
Adding an XCFramework
-
Drag it into your project
Drag
Chilkat.xcframeworkinto the Xcode Project Navigator, or add it under General → Frameworks, Libraries, and Embedded Content with the + button. -
Set "Do Not Embed"
Because Chilkat is a static library, set the embed option to Do Not Embed. (Static code is linked into your app binary; there is nothing to embed as a separate bundle.)
-
Headers come with it
The XCFramework includes the Chilkat headers, so a separate Header Search Path is normally not needed. Import headers in your code as shown under Using & unlocking.
-
Add the linker flags
Add the required flags to Other Linker Flags — see below.
Other Linker Flags
Chilkat depends on a few system libraries. In Build Settings → Other Linker Flags, add:
-lresolv -lpthread -lc++
-lresolv— the DNS resolver library (used for networking).-lpthread— POSIX threads.-lc++— the LLVM C++ standard library.
Swift projects: add a bridging header
Chilkat's iOS interface is Objective-C, so Swift code reaches it through a bridging header.
-
Create the bridging header
Add a header named
YourProject-Bridging-Header.hand import the ChilkatCkoclasses your app uses:#import <Foundation/NSObject.h> #import "chilkat-ios/include/CkoGlobal.h" #import "chilkat-ios/include/CkoJsonObject.h" #import "chilkat-ios/include/CkoHttp.h" // Import each Cko*.h header your app uses. The path depends on // where you extracted the Chilkat headers.
-
Point Xcode at it
Set Build Settings → Objective-C Bridging Header to the path of that file. Swift can then call the Chilkat classes directly.
Using & unlocking Chilkat
Chilkat runs as a fully functional 30-day trial out of the box. Unlock it
once at startup by calling UnlockBundle on a CkoGlobal
object — pass any non-empty string for the trial, or your license code after
purchase.
#import "CkoGlobal.h" #import "CkoJsonObject.h" // Call once, at application startup. CkoGlobal *glob = [[CkoGlobal alloc] init]; BOOL success = [glob UnlockBundle: @"Anything for 30-day trial"]; if (!success) { NSLog(@"%@", glob.LastErrorText); return; } // Use any Chilkat class. CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"author.name" value: @"Chilkat"]; NSLog(@"%@", [json Emit]);
In C++, the equivalent is CkGlobal glob; glob.UnlockBundle("..."); using
the cpp_include headers.
Memory management & ARC
All objects returned by Chilkat methods — including NSString,
NSNumber, NSData, NSMutableData,
NSDate, and Cko Chilkat objects — are autoreleased.
Your application does not need to release them.
The Chilkat library works with ARC (Automatic Reference Counting) enabled.
Additional notes
The static library is only needed at link time
A static library (.a), and a static XCFramework, are used only when
building your app. At link time the referenced Chilkat code is copied directly
into your application's executable. You do not ship or install
libchilkatIos.a (or Chilkat.xcframework) with your app, and
there is nothing for the end user to install — this is also why an XCFramework
is added with Do Not Embed.
About the size of the static library
A static linker compiles into your executable only the library code that is directly
or indirectly referenced. Your application binary is the same size regardless of how
the library is arranged — as one large library or several smaller ones —
so the size of libchilkatIos.a on disk does not reflect how much is added
to your app.
Bitcode
Bitcode has been removed from Xcode (deprecated in Xcode 14) and is no longer required or accepted by the App Store. If you use an older Xcode that still has the setting, set Enable Bitcode to No.