xcode 为 iPhone 编译 C 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3610107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compile C lib for iPhone
提问by Dan
I'm trying to compile ZeroMQ C binding in order to be able to use it on iPhone, here is my configure options:
我正在尝试编译 ZeroMQ C 绑定以便能够在 iPhone 上使用它,这是我的配置选项:
./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 CFLAGS="-pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.1.2 -gdwarf-2 -mthumb -I/Library/iPhone/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -mdynamic-no-pic" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib
./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 CFLAGS="-pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.1.2 -gdwarf-2 -mthumb -I/Library/iPhone/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -mdynamic-no-pic" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib
It actually configures and compiles fine, but when I add it to Xcode Frameworks section, I get warning: ld: warning: in /path/to/app/libzmq.a, file was built for unsupported file format which is not the architecture being linked (armv7)
and a lot of symbol not found errors.
它实际上配置和编译得很好,但是当我将它添加到 Xcode Frameworks 部分时,我收到警告:ld: warning: in /path/to/app/libzmq.a, file was built for unsupported file format which is not the architecture being linked (armv7)
并且有很多符号未找到错误。
If I change current active architecture from armv6 to armv7, warning message will change it to armv6. What am I doing wrong ?
如果我将当前活动架构从 armv6 更改为 armv7,警告消息会将其更改为 armv6。我究竟做错了什么 ?
Thanks, Dan
谢谢,丹
回答by Jesse Beder
It sounds like you're building a universal armv6/armv7 binary for the iPhone (this is the default, so that makes sense). That means that you need to build a universal library to link against. Build bothlibraries, and then use lipo
to combine the two.
听起来您正在为 iPhone 构建一个通用的 armv6/armv7 二进制文件(这是默认设置,所以这是有道理的)。这意味着您需要构建一个通用库来链接。构建两个库,然后使用lipo
将两者结合起来。
For example, build the armv6 one and place it at armv6/libfoo.a
, and the armv7 one at armv7/libfoo.a
. Then run
例如,构建 armv6 并将其放置在armv6/libfoo.a
,将 armv7 构建为armv7/libfoo.a
。然后运行
lipo -arch armv6 armv6/libfoo.a -arch armv7 armv7/libfoo.a -output libfoo.a -create
to create the universal library libfoo.a
.
创建通用库libfoo.a
。
回答by Shaggy Frog
Given the warning message from ld
, my guess is you're not compiling the library for the correct platform. And given you're using configure
, my guess is you're trying to compile the library outside of Xcode and then bring it into Xcode later to link it in.
鉴于来自 的警告消息ld
,我的猜测是您没有为正确的平台编译库。鉴于您正在使用configure
,我的猜测是您正在尝试在 Xcode 之外编译库,然后稍后将其带入 Xcode 以链接它。
Perhaps you could try running configure to set up your headers, but do the actual compilation step inside Xcode?
也许您可以尝试运行 configure 来设置您的标头,但是在 Xcode 中执行实际的编译步骤?
There are lots of related questions here on SO about compiling third-party (external) C or C++ libraries for use in iPhone projects.
这里有很多关于编译第三方(外部)C 或 C++ 库以用于 iPhone 项目的相关问题。
Creating static library for iPhone