2010-05-28 151 views
9

我已經構建了自己的靜態庫,其組件可以在我的項目中重用,並且最近需要更新一堆類。具體而言,由於某些類改名,某些方法的簽名發生了變化。iPhone SDK鏈接錯誤與靜態庫

現在發生的是,庫編譯對自己很好,但是,當添加到應用程序的項目,該項目未能鏈接:

Ld build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales normal armv6 
cd /Users/nameghino/src/Sucursales 
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1 
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" 
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -L/Users/nameghino/src/Sucursales/build/Debug-iphoneos -L/Users/nameghino/src/Sucursales/../../Library/MyLibraries/MSSharedLibrary-1.0.0 -F/Users/nameghino/src/Sucursales/build/Debug-iphoneos -filelist /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales.LinkFileList -dead_strip -lxml2 -ObjC -all_load -miphoneos-version-min=3.1 -framework Foundation -framework UIKit -framework CoreGraphics -lsqlite3.0 -framework CoreLocation -framework MapKit -lxml2 /Users/nameghino/src/MSSharedComponents/Frameworks/MSSharedLibrary/build/Debug-iphoneos/libMSSharedLibrary.a -o /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales 

Undefined symbols: 
    "_OBJC_CLASS_$_DataCatalogService_GetSingleRow", referenced from: 
     objc-class-ref-to-DataCatalogService_GetSingleRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o) 
    **"_OBJC_CLASS_$_DataCatalogService_ArrayOfString", referenced from: 
     objc-class-ref-to-DataCatalogService_ArrayOfString in libMSSharedLibrary.a(MSDataCatalogSpecification.o) 
    "_OBJC_CLASS_$_DataCatalogService_GetSingleRowResponse", referenced from: 
     objc-class-ref-to-DataCatalogService_GetSingleRowResponse in libMSSharedLibrary.a(MSSingleRowResultsParser.o) 
    "_OBJC_CLASS_$_DataCatalogService_GetMultiRowResponse", referenced from: 
     objc-class-ref-to-DataCatalogService_GetMultiRowResponse in libMSSharedLibrary.a(MSMultiRowResultsParser.o) 
    "_OBJC_CLASS_$_DataCatalogService_GetMultiRow", referenced from: 
     objc-class-ref-to-DataCatalogService_GetMultiRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o) 
    "_OBJC_CLASS_$_DataCatalogService_HelloWorldResponse", referenced from: 
     objc-class-ref-to-DataCatalogService_HelloWorldResponse in libMSSharedLibrary.a(DataCatalogService.o) 
ld: symbol(s) not found 
collect2: ld returned 1 exit status** 

好奇的是,經過大量的項目清理的(無論是在應用程序和lib項目中),我仍然遇到同樣的問題。即使開始一個新項目,問題仍然存在。

我也注意重新啓動Xcode之間的乾淨和建立幾次,但沒有好處。

任何想法去哪裏看?

回答

6

您是否將庫作爲依賴項添加到項目中?請參閱Xcode 3.1.1 and static libraries

如果深入瞭解目標,庫名是否顯示在「帶庫鏈接二進制文件 」組中?

查看編譯器/鏈接器輸出的日誌。找到對鏈接器的調用。您的圖書館是否出現在要鏈接的靜態圖書館列表中?

+3

感謝您的回答! 是的,該庫是該項目的依賴項。 是的,庫名稱位於「鏈接庫與二進制文件」組中。 是的,事實上,鏈接器調用在上面的pastie中。 – Nico 2010-05-31 15:05:49

0

我剛剛遇到相同的鏈接器錯誤。我通過反覆試驗發現,這是因爲我調用了isKindOfClass。我不知道爲什麼這會導致鏈接器barf,但希望這些信息幫助。

有問題的類OrderItem是NSManagedObject的子類;換句話說,它是一個自動生成的核心數據實體類。

具體地,這裏是接頭錯誤:

"_OBJC_CLASS_$_OrderItem", referenced from: 
objc-class-ref-to-OrderItem in libmyStaticLib.a(MyTableViewController.o) 
ld: symbol(s) not found 
collect2: ld returned 1 exit status 

在這裏被有問題的代碼:

- (void)handleButtonTapWithObject:(id)object 
{ 
    // This must be an OrderItem or else we don't want to touch it: 
    if (NO == [object isKindOfClass:[OrderItem class]]) // <-- OFFENDING CODE 
    { 
     NSLog(@"Object parameter is of unexpected type."); 
     return; 
    } 

我的解決方法是簡單地省略,以確保「對象」是一個OrderItem的測試。沒有這個測試,代碼並不安全,但鏈接錯誤消失了。我很想知道我是否正在進行這種測試是錯誤的,也許有更好的方法來做到這一點。

0

我剛剛發現,如果您使用xcode 4,您應該拖放庫項目,然後轉到您的目標設置,然後在鏈接框架和庫的摘要選項卡中添加您的庫並完成。

希望它能幫助別人。

2

是的我解決了這個錯誤..非常感謝@Shaggy青蛙

錯誤

我用一些YouTube的類和它的給我下面的錯誤

enter image description here

解決方案

我們需要添加在「構建階段」選項中將Lib類設置爲「Compiler Sources」。

  1. 轉到項目的構建階段並點擊編譯器源選項(見下圖)。 enter image description here

  2. 然後添加類在這裏

現在做項目清潔,去構建。

希望它有幫助:)