【问题标题】:Xcode static library seems to change architecture on buildXcode 静态库似乎在构建时改变了架构
【发布时间】:2017-06-14 06:11:43
【问题描述】:

在我深入探讨这个问题之前,这里有一些背景知识。我的最终目标是为 arm64、armv7、armv7s、i386 和 x86_64 架构编译一个 c++ 静态库的源代码,然后将这些库打包成一个胖库,以便在 iOS 开发过程中使用它们。这将使我能够使用模拟器和具有相同库的设备。

这是我的问题。我正在尝试使用 iPhone 5 模拟器单独测试 i386 版本的库。我为 i386 编译了静态库如下:

./configure --enable-utf8-only --disable-shared --host=i386-apple-darwin LDFLAGS="-L." CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" CXX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"

然后

make CXXFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk" CCFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk"

这导致了我的静态库libtest.a。然后我运行以下命令来验证库架构

jamespc:Desktop $ lipo -info libtest.a 
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: i386

到目前为止,一切看起来都不错。接下来,我将库添加到我的 Xcode 项目中并尝试构建该项目。在构建项目时,我收到以下警告和错误。

ld: warning: ignoring file 
    /Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a,
    file was built for archive which is not the architecture being linked (i386):
    /Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a
Undefined symbols for architecture i386:
    ...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

被错误弄糊涂了,我再次在我的静态库上运行了 lipo,这次使用的是警告中列出的路径,在派生数据文件夹中。

jamespc:Debug-iphonesimulator $ lipo -info libtest.a 
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: x86_64

当我在派生数据中查看该库时,为什么该库似乎具有与之关联的不同架构,我对此感到困惑。

我编译静态库的方式错了吗? 在我的 Xcode 构建设置中我可能做错了什么吗? 感谢您花时间阅读我的问题

【问题讨论】:

标签: c++ ios iphone xcode


【解决方案1】:

我猜这个框架不是为 iOS Simulator 的架构编译的,也就是 i386。 Xcode 只为目标架构编译一个框架。

请按照本教程进行操作:http://www.raywenderlich.com/65964/create-a-framework-for-ios

这可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2019-07-14
    • 2011-12-06
    • 2019-11-16
    • 1970-01-01
    • 2011-08-09
    • 2015-08-06
    • 1970-01-01
    相关资源
    最近更新 更多