[英]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.