cross compile libcurl to run on ios simulator

367 Views Asked by At

I need to cross compile libcurl so that I can use its API from within an iOS app running on the Xcode iOS simulator. I have a simple app in swift that calls out to a C driver function, which then contains some calls into libcurl. I already have the appropriate bridging headers set up so the C interoperability works, I just need to link against libcurl now.

Unfortunately, after days of struggling I still can't get the cross compilation of libcurl correct, such that my app can link against it.

Note: I am compiling on an Macbook pro (m1 pro apple silicon) with MacOS Ventura 13.4

Darwin XXX-MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64

I'm configuring curl with this call to ./configure:

./configure --prefix /path/to/install \
   --enable-static --disable-shared \
   --with-secure-transport 
   --host=arm64-apple-darwin \
   CFLAGS="-arch arm64 -target arm64-apple-ios-simulator -isysroot $(xcrun -sdk iphonesimulator --show-sdk-path) -miphonesimulator-version-min=16.4"

make -j
make install

Everything configures and builds fine, but when I drag the produced static library into my app's xcode project (which I confirmed does add libcurl.a as a linked library) I get the following build error in xcode:

In /Path/to/libcurl.a(libcurl_la-altsvc.o), building for iOS Simulator, but linking in object file built for macOS, file '/Path/to/libcurl.a' for architecture arm64

My questions:

  1. Why does xcode think this object file is built for macOS? The cross compilation options passed to ./configure through CFLAGS should mean it is cross compiled to run on the iOS simulator
  2. What are the bare-minimum compile options (passed directly to clang/gcc) required to cross compile anything such that it can be pulled into xcode and run on the iOS simulator?
  3. What is the appropriate invocation to curl's ./configure such that I can create a static library for libcurl and import it into my xcode project?
0

There are 0 best solutions below