简体   繁体   English

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

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

Here's a bit of background before I dive into the question. 在我深入探讨这个问题之前,这里有一些背景知识。 My ultimate goal is to compile the source of a c++ static library for the architectures arm64, armv7, armv7s, i386, and x86_64, and then package the libraries into a fat library so that I can use them during iOS development. 我的最终目标是编译用于体系结构arm64,armv7,armv7s,i386和x86_64的c ++静态库的源,然后将这些库打包到胖库中,以便在iOS开发期间可以使用它们。 This will enable me to use the simulator and a device with the same library. 这将使我能够使用模拟器和具有相同库的设备。

Here's my issue. 这是我的问题。 I'm trying to test the i386 version of the library, on it's own, using the iPhone 5 simulator. 我正在尝试使用iPhone 5模拟器单独测试i386版本的库。 I compiled the static library for i386 as follows: 我为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++"

then 然后

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"

This resulted in my static library, libtest.a . 这产生了我的静态库libtest.a I then ran the follow to verify the libraries architecture 然后,我运行以下命令来验证库体系结构

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

Everything seemed to look good so far. 到目前为止,一切看起来都不错。 Next I added the library to my Xcode project and tried to build the project. 接下来,我将该库添加到我的Xcode项目中,并尝试构建该项目。 When building the project I get the following warning and error. 生成项目时,出现以下警告和错误。

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)

Perplexed by error I ran lipo on my static lib again, this time using the path listed in the warning, in the derived data folder. 由于错误而感到困惑,这次我再次在我的静态库上运行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

I'm confused as to why the library appears to have a different architecture associated with it when I take a look at it in the derived data. 当我在派生数据中查看库时,为什么对库似乎具有与之关联的不同体系结构感到困惑。

Is the way I'm compiling the static library wrong? 我编译静态库的方式是否错误? Is there something I might be doing wrong in my Xcode build settings? Xcode构建设置中我可能做错了什么吗? Thank you for taking the time to read my question 感谢您抽出宝贵时间阅读我的问题

I guess the framework was not compiled for the iOS Simulator's architecture, which is i386. 我猜该框架没有针对iOS Simulator的架构i386进行编译。 Xcode only compiles a framework for the target architecture. Xcode仅编译用于目标体系结构的框架。

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

It may help. 这可能会有所帮助。

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

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