繁体   English   中英

Xcode静态库似乎改变了构建的体系结构

[英]Xcode static library seems to change architecture on build

在我深入探讨这个问题之前,这里有一些背景知识。 我的最终目标是编译用于体系结构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构建设置中我可能做错了什么吗? 感谢您抽出宝贵时间阅读我的问题

我猜该框架没有针对iOS Simulator的架构i386进行编译。 Xcode仅编译用于目标体系结构的框架。

请遵循以下教程: http : //www.raywenderlich.com/65964/create-a-framework-for-ios

这可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM