我需要交叉编译
libcurl
,以便我可以在 Xcode iOS 模拟器上运行的 iOS 应用程序中使用它的 API。我有一个简单的 swift 应用程序,它调用 C 驱动程序函数,然后该函数包含一些对 libcurl 的调用。我已经设置了适当的桥接标头,因此 C 互操作性可以正常工作,我现在只需要链接到 libcurl
。
不幸的是,经过几天的努力,我仍然无法正确交叉编译
libcurl
,以便我的应用程序可以链接到它。
注意:我正在使用 MacOS Ventura 13.4 的 Macbook pro(m1 pro 苹果硅)上进行编译
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
我正在通过对
curl
的调用来配置 ./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
一切配置和构建都很好,但是当我将生成的静态库拖到我的应用程序的 xcode 项目中(我确认确实将
libcurl.a
添加为链接库)时,我在 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
./configure
传递给 CFLAGS
的交叉编译选项应该意味着它是交叉编译的,可以在 iOS 模拟器上运行./configure
的适当调用是什么,以便我可以为libcurl
创建静态库并将其导入到我的xcode项目中?构建curl 8的构建说明位于curl页面
export ARCH=arm64
export SDK=iphoneos
export DEPLOYMENT_TARGET=12.0
sudo xcode-select --switch /Applications/Xcode.app
export CFLAGS="-arch $ARCH -isysroot $(xcrun -sdk $SDK --show-sdk-path) -m$SDK-version-min=$DEPLOYMENT_TARGET"
./configure 不在 github 中,而是在 libcurl 下载中
./configure --host=$ARCH-apple-darwin --prefix $(pwd)/artifacts --with-secure-transport
make -j8
make install
构建结果位于
artifacts
文件夹中