交叉编译libcurl以在ios模拟器上运行

问题描述 投票:0回答:1

我需要交叉编译

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

我的问题:

  1. 为什么 xcode 认为这个目标文件是为 macOS 构建的?通过
    ./configure
    传递给
    CFLAGS
    的交叉编译选项应该意味着它是交叉编译的,可以在 iOS 模拟器上运行
  2. 交叉编译anything所需的最低限度编译选项是什么(直接传递给clang/gcc),以便可以将其拉入xcode并在iOS模拟器上运行?
  3. 对curl的
    ./configure
    的适当调用是什么,以便我可以为
    libcurl
    创建静态库并将其导入到我的xcode项目中?
ios xcode ios-simulator libcurl autotools
1个回答
0
投票

构建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
文件夹中

© www.soinside.com 2019 - 2024. All rights reserved.