为 iPhone 编译 C lib
我正在尝试编译 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 它
实际上配置和编译得很好,但是当我将它添加到 Xcode Frameworks 部分时,我收到警告: ld: warning: in /path/to/app/libzmq.a, file wasbuilt for unsupported file格式不是正在链接的体系结构(armv7),并且有很多符号未找到错误。
如果我将当前活动架构从armv6更改为armv7,警告消息会将其更改为armv6。 我做错了什么?
谢谢, 担
I'm trying to compile ZeroMQ C binding in order to be able to use it on iPhone, here is my configure options:
./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.
If I change current active architecture from armv6 to armv7, warning message will change it to armv6.
What am I doing wrong ?
Thanks,
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您正在为 iPhone 构建通用的 armv6/armv7 二进制文件(这是默认设置,所以这是有道理的)。这意味着您需要构建一个通用库来链接。构建两个库,然后使用
lipo
将两者结合起来。例如,构建armv6 并将其放置在
armv6/libfoo.a
中,将armv7 放置在armv7/libfoo.a
中。然后运行创建通用库
libfoo.a
。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 both libraries, and then use
lipo
to combine the two.For example, build the armv6 one and place it at
armv6/libfoo.a
, and the armv7 one atarmv7/libfoo.a
. Then runto create the universal library
libfoo.a
.鉴于来自 ld 的警告消息,我的猜测是您没有为正确的平台编译该库。考虑到您正在使用
configure
,我的猜测是您正在尝试在 Xcode 之外编译该库,然后稍后将其引入 Xcode 中以链接它。也许您可以尝试运行 configure 来设置你的头文件,但是在 Xcode 中执行实际的编译步骤吗?
这里有很多关于编译第三方(外部)C 或 C++ 库以在 iPhone 项目中使用的相关问题。
为 iPhone 创建静态库
TiMidity:需要帮助为 iPhone 编译此库
Given the warning message from
ld
, my guess is you're not compiling the library for the correct platform. And given you're usingconfigure
, my guess is you're trying to compile the library outside of Xcode and then bring it into Xcode later to link it in.Perhaps you could try running configure to set up your headers, but do the actual compilation step inside Xcode?
There are lots of related questions here on SO about compiling third-party (external) C or C++ libraries for use in iPhone projects.
Creating static library for iPhone
TiMidity: need help compiling this library for the iPhone