如何配置库以便它在 Xcode iOS 模拟器中运行?
我有一个在设备上运行的 iPhone 应用程序。现在我需要在模拟器中运行它。
它使用开源项目(http://site.icu-project.org/),我从命令行构建它来创建与arm兼容的.a
文件。我可以将它们与我的 iPhone 项目链接,然后它在设备上运行。
如果我将目标切换到模拟器,构建就会失败,正如我所料:
ld:警告:在 libicudata.a 中,文件是为不受支持的文件格式构建的,该格式不是 链接的架构(i386)
但是如果我使用为本地使用而编译的库(x86_64),我会得到相同的错误,这让我感到困惑。我是否必须为模拟器指定第三种架构?哪一个?如何设置配置?
作为参考,这是我为两个不同目标配置 icu 项目的方法:如何构建 ICU 以便我可以在 iPhone 应用程序中使用它?< /a>
编辑添加:
正如 Guillaume 建议的那样(并且使用 Libpq 将 iPhone 应用程序连接到 PostgreSQL 已确认) , 我现在看到模拟器需要 32 位版本。这就是最后一部分:如何设置配置?
据我所知,该库有一个标准的 configure
脚本,但我对此还很陌生。
编辑添加:
我已经讲到这里了,但是对 i686 的引用显然是错误的。
我不知道 i386 是否被认为是交叉编译,如果是,我也需要“主机”和“目标”选项。
ICU_PATH=/Users/eric.grunin/Documents/dev/icu2
DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.3.sdk
SYSROOT=$SDKROOT
ICU_FLAGS="-I$ICU_PATH/source/common/ -I$ICU_PATH/source/tools/tzcode/ "
export CXXPP=
export CXXPPFLAGS=
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/ -I$SDKROOT/usr/include/c++/4.2.1/armv7-apple-darwin10/ -I./include/ -miphoneos-version-min=2.2 $ICU_FLAGS"
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS"
export CXXFLAGS="$CFLAGS"
export CC="$DEVROOT/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-gcc-4.2"
export CXX="$DEVROOT/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-g++-4.2"
export LDFLAGS="-L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip -miphoneos-version-min=2.0"
cd $ICU_PATH
mkdir simbuild
cd simbuild
$ICU_PATH/source/configure --enable-static --disable-shared
gnumake
I've got an iPhone app that runs on the device. Now I need to run it in the Simulator.
It uses an open source project (http://site.icu-project.org/), which I build from the command line to create arm-compatible .a
files. I can link these with my iPhone project, and it runs on the device.
If I switch the target to Simulator, the build fails, as I expected:
ld: warning: in libicudata.a, file was built for unsupported file format which is not the
architecture being linked (i386)
But if I use libs compiled for local use (x86_64), I get the same error, which has got be baffled. Do I have to specify a third architecture for the Simulator? Which one? How do I set the configuration?
For reference, this is how I configured the icu project for the two different targets: How to build ICU so I can use it in an iPhone app?
Edited to add:
As Guillaume suggested (and Connect iPhone App to PostgreSQL Using Libpq confirmed), I now see that the emulator needs a 32-bit build. So that's the last part: how do I set the configuration?
The library has a standard configure
script, as far as I know, but I'm still pretty new at this.
Edited to add:
I've gotten this far, but the references to i686 are obviously wrong.
I don't know if i386 is considered a cross-compile, if it is I need "host" and "target" options, too.
ICU_PATH=/Users/eric.grunin/Documents/dev/icu2
DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.3.sdk
SYSROOT=$SDKROOT
ICU_FLAGS="-I$ICU_PATH/source/common/ -I$ICU_PATH/source/tools/tzcode/ "
export CXXPP=
export CXXPPFLAGS=
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/ -I$SDKROOT/usr/include/c++/4.2.1/armv7-apple-darwin10/ -I./include/ -miphoneos-version-min=2.2 $ICU_FLAGS"
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS"
export CXXFLAGS="$CFLAGS"
export CC="$DEVROOT/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-gcc-4.2"
export CXX="$DEVROOT/usr/llvm-gcc-4.2/bin/i686-apple-darwin10-llvm-g++-4.2"
export LDFLAGS="-L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip -miphoneos-version-min=2.0"
cd $ICU_PATH
mkdir simbuild
cd simbuild
$ICU_PATH/source/configure --enable-static --disable-shared
gnumake
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要构建一个胖库:胖库是一种将多种架构的代码嵌入到一个文件中的库。
对于设备,您需要添加架构
armv6
和armv7
。对于模拟器,i386
。查看此答案以获取详细信息以及有关如何从 Xcode 执行此操作的脚本:https://stackoverflow.com/a/3647187/272342
You need to build a fat library: a fat library is a library that embed the code of many architectures in one file.
For the devices, you need to add the architectures
armv6
andarmv7
. For the simulator,i386
.Look into this answer for details and a script on how to do this from Xcode: https://stackoverflow.com/a/3647187/272342
这只是数据库。您不需要多次构建它。在构建 ICU 时使用
--with-data-packaging=archive
,然后它将生成一个文件icudt*.dat
.. 当您的应用程序启动时,调用 < code>u_setDataDirectory() 告诉它哪个目录包含该 .dat 文件。 u_setDataDirectory()That's just the data library. You don't need to build it several times. Use
--with-data-packaging=archive
when you build ICU, and then it will generate a fileicudt*.dat
.. when your app starts up, callu_setDataDirectory()
to tell it which directory contains that .dat file. u_setDataDirectory()这就是我让它发挥作用的方式。我把它放在这里,以便我以后可以查找。
可能有不完善的地方,欢迎指正。评论试图将我正在构建的 ICU 库的通用内容与特定内容区分开来。
我可能不会制作一个胖二进制文件,因为 ICU 库已经非常大,我需要使最终的应用程序尽可能小。
编辑添加
我尝试了胖库方法:它增加了三倍我的应用程序的大小,唉。
This is how I got it to work. I'm putting it here so I can look it up later.
It's likely this is imperfect, feel free to correct it. Comments try to separate what's generic from what's specific to the ICU library I was building.
I'm probably not going to make a fat binary, because the ICU library is already very large and I need to keep the final app as small as possible.
Edited to add
I tried the fat library approach: it tripled the size of my app, alas.