【发布时间】: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 构建设置中我可能做错了什么吗? 感谢您花时间阅读我的问题
【问题讨论】:
-
嘿 James.libtest.a 是架构:i386 错误意味着胖文件不包含 i386 支持。请参考视频youtube.com/watch?v=j_SQ8zw0Sq0