【问题标题】:Compile C lib for iPhone为 iPhone 编译 C 库
【发布时间】:2010-08-31 14:43:04
【问题描述】:

我正在尝试编译 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 框架部分时,我收到警告:ld: warning: in /path/to/app/libzmq.a, file was built for unsupported file format which is not the architecture being linked (armv7) 和很多未找到符号的错误。

如果我将当前活动架构从 armv6 更改为 armv7,警告消息会将其更改为 armv6。 我做错了什么?

谢谢, 丹

【问题讨论】:

    标签: iphone xcode compilation configure zeromq


    【解决方案1】:

    听起来您正在为 iPhone 构建通用 armv6/armv7 二进制文件(这是默认设置,所以有意义)。这意味着您需要构建一个通用库来链接。构建两个库,然后使用lipo 将两者结合起来。

    例如,构建 armv6 并将其放置在 armv6/libfoo.a,将 armv7 放置在 armv7/libfoo.a。然后运行

    lipo -arch armv6 armv6/libfoo.a -arch armv7 armv7/libfoo.a -output libfoo.a -create
    

    创建通用库libfoo.a

    【讨论】:

    • 感谢您的回答,但我该如何定义架构? arm-apple-darwin10-gcc-4.2.1 不理解 -arch 选项。顺便说一句,我的 lib 的 lipo -info 说是为 x86_64 编译的,这很奇怪。
    • 抱歉,我没有注意到您没有通过 -arch 选项。我不确定它为什么不接受它,但为什么不尝试使用 /Developer/Platforms/.../gcc 代替呢?我刚刚查找了我使用过的 C 库的配置命令,并且通常有效。
    • 谢谢,我终于能够使用这个问题的脚本正确编译它了 - stackoverflow.com/questions/1602182/…
    【解决方案2】:

    鉴于来自ld 的警告消息,我猜你没有为正确的平台编译库。鉴于您使用的是configure,我猜您正在尝试在 Xcode 之外编译该库,然后稍后将其引入 Xcode 以将其链接。

    也许您可以尝试运行 configure 来设置您的标头,但在 Xcode 中执行实际的编译步骤?

    这里有很多关于编译第三方(外部)C 或 C++ 库以用于 iPhone 项目的相关问题。

    Creating static library for iPhone

    TiMidity: need help compiling this library for the iPhone

    【讨论】:

    猜你喜欢
    • 2011-07-17
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多