2017-06-14 78 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 –

回答