2017-06-14 77 views
0

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

这是我的问题。我试图使用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) 

困惑的错误我使用导出的数据文件夹中的警告列出的路径,又跑到脂在我的静态库,这个时候。

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构建设置中可能会出现错误吗? 感谢您花时间阅读我的问题

+0

嘿James.libtest.a是体系结构:i386错误,意思是fat文件不包含i386支持。请参阅视频https://www.youtube.com/watch?v=j_SQ8zw0Sq0 –

回答