2012-05-16 180 views
2

我想構建我的第一個靜態庫,並且遇到了編譯問題。我的意思是我可以編譯我的圖書館和每一件事情看起來不錯,但是當我建立了一個測試項目來測試它,我得到了這樣那樣的錯誤:iOS:編譯靜態庫

ld: warning: ignoring file /Users/*/Desktop/TestApp/LibProva/libProva.a, file was built for archive which is not the architecture being linked (i386) Undefined symbols for architecture i386: "_OBJC_CLASS_$_Prova", referenced from: objc-class-ref in AppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld: warning: ignoring file /Users/**/Desktop/TestApp/LibProva/libProva.a, file was built for archive which is not the architecture being linked (i386)

所以我想這就是有毛病編譯(因不同在模擬器和設備中的架構),但我無法找到如何以正確的方式做到這一點。有人能解釋我如何解決這個問題嗎?

回答

2

必須使用脂創建一個通用二進制:

#!/bin/bash 
#build the device 
echo building for ARM architecture 
xcodebuild -sdk iphoneos4.3 "ARCHS=armv6 armv7" build > /dev/null 
#build the simulator 
echo building for the i386 architecture 
xcodebuild -sdk iphonesimulator4.3 "ARCHS=i386 x86_64" "VALID_ARCHS=i386 x86_64" build > /dev/null 
#make the folder 
mkdir "Fat Binary" 
#lipo suck it together 
echo lipo binaries together 
lipo -output Fat\ Binary/libmylib.a -create build/Release-iphoneos/libprefuse_visual_iOS.a build/Release-iphonesimulator/libmylib.a 
echo lipo binary saved at $./Fat Binary/libmylib.a 
echo copying headers 
cp -R build/Release-iphoneos/usr "Fat Binary" 
echo [COMPLETE] 

務必更換的情況下, libmylib.a與由xcodebuild生成的.a的實際名稱。