使用适用于iPhone模拟器的arch i386编译C库?

时间:2015-07-15 06:59:01

标签: ios objective-c c xcode simulator

我正在为Xcode项目制作一个C库,并使用-arch armv7成功编译,它可以在iPhone设备上使用。这是我使用的命令:

./configure \
--host=arm-apple-darwin \
CFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk" \
CXXFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk" \
LDFLAGS="-L." \
CC="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" \
CXX="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

然后make

我做了同样的事情来编译armv7sarm64架构。使用-arch i386时,我无法再将-isysrootiPhoneOS.platform一起使用,我猜因为iPhoneOS不支持i386,所以我更改为iPhoneSimulator.platform

./configure \
--host=arm-apple-darwin \
CFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" \
CXXFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" \
LDFLAGS="-L." \
CC="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" \
CXX="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

但它仍然无效。当我尝试使用iPhoneOS.platform编译i386时出现同样的错误:

checking whether the C compiler works... no
configure: error: C compiler cannot create executables

似乎iPhoneSimulator也不支持i386?!当我使用armv7 lib for iPhone模拟器时,它说缺少i386架构的符号,所以我非常确定iPhone模拟器支持i386。

任何人都知道如何为模拟器编译lib?或者有一种更简单的方法,将源代码(如this repo)导入Xcode,然后让它为所有架构构建通用库?从现在起,我必须为每个arch构建每个lib,然后使用lipo组合它们。

2 个答案:

答案 0 :(得分:1)

经过几个小时的搜索,我终于找到了解决方案:Apple用工具链中的clang取代了gcc,并添加了一个" -triple"将OSX指定为目标的选项。如果我们向-miphoneos-version-min=8.0CFLAGS添加CXXFLAGS(或任何您想要的版本),那么它就知道目标是iOS并让我们编译。请务必在iPhoneSimulator.platform中使用-isysroot

答案 1 :(得分:0)

尝试强制编译器为gcc。希望有所帮助。

CC="/usr/bin/clang" \
CXX="/usr/bin/clang++"
相关问题