1. 程式人生 > >xcode上編譯c語言程序報錯:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

xcode上編譯c語言程序報錯:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

text internal self. value gen scrip info 內容 讀取

技術分享圖片

技術分享圖片

在網上查了一下:

duplicate symbol的大概意思是,編譯器認為你重復定義了一些東西。

linker command failed with exit code 1,則可能是項目引入了多個相同的文件。

結合本人開發中發現此類的問題,解決辦法如下:

方法1:查看有問題的文件是否有重復引用。或頭文件是否加載了.m

方法2:將有問題的文件刪除,重新加載進去。然後:clean->build.

在開發中解決RegexKitlLite的類似問題辦法:

_rkl_NSExceptionForRegex in RegexKitLite.o

"_u_strlen", referenced from:

_rkl_userInfoDictionary in RegexKitLite.o

"_uregex_clone", referenced from:

-[RKLBlockEnumerationHelper initWithRegex:options:string:range:error:]in RegexKitLite.o

ld: symbol(s) not found for architecture i386

collect2: ld returned 1 exit status

解決辦法:

在項目的編譯設置中找到Other Linker Flags,然後在後面字段空白處雙擊,添加“-licucore”就ok了。

開發中常見問題總結:

一下內容均為個人學習使用,有不足之處請拍磚。

使用代碼創建窗口,沒有反應,無法進入 didFinishLaunchingWithOptions方法.

報錯描述:使用代碼創建窗口,沒有反應,無法進入 didFinishLaunchingWithOptions方法.

報錯原因:沒有正確重寫didFinishLaunchingWithOptions方法,或者修改錯寫了方法沒發現

解決方案:正確重寫didFinishLaunchingWithOptions方法


reason: ‘couldn‘t find a common superview for ...UILabel:0x7f8ec05c3ab0 frame = (0 0; 0 0);

報錯原因 couldn‘t find a common superview for ... frame = (0 0; 0 0);使用masonry前沒有把對象加入父控件

解決方案:在masonry控制對象約束前把對象增加進入某控件

[self.viewaddSubview:label];



Duplicate declaration of method 錯誤原因:復制方法的聲明(重復定義,重復聲明)

duplicate symbols for architecture 錯誤原因:重復導入.m文件或者錯誤import .m文件

解決方案:刪除相同的聲明,定義


Application windows are expected to have a root view controller at the end of application launch‘

報錯原因:沒有設置窗口的根控制器

解決方案:self.window.rootViewController= VC;//設置根控制器


Could not find a storyboard named ‘main‘ in bundle NSBundle

報錯原因:沒有找到名稱為main 的storyboard 默認是Main.storyboard

解決方案:UIStoryboard*storyboard = [UIStoryboardstoryboardWithName:@"main"bundle:nil];m改成大寫


CUICatalog: Invalid asset name supplied: (null)

報錯原因:Incompatible pointer types sending ‘UIImage *‘ to parameter of type ‘NSString * _Nonnull‘

模型類型與視圖使用模型設置數據時不匹配

解決方案: 檢查模型類型,使得視圖對象裏使用其時一致。


錯誤描述 : Static table views are only valid when embedded in UITableViewController instances

錯誤原因 : 錯誤的使用了talbe View的靜態cell , 靜態的cell只能在 UITableViewController 的實例對象 中使用

解決方案 : 使用動態的cell ,在table View的屬性content 中選擇Dynamic prototypes


configureCellForDisplay:forIndexPath沒有綁定Identifier

錯誤描述:-[UITableView _configureCellForDisplay:forIndexPath:]

Terminating app due to uncaught exception ‘NSInternalInconsistencyException‘, reason: ‘UITableView後面一堆UITableView的屬性

錯誤原因:沒有分配,綁定cellForRowAtIndexPath方法中對象cell的ID,導致對象沒有創建

解決方案:分配,綁定storyboard中tableViewCell的屬性ID同創建cellID


[約束警告] Unable to simultaneously satisfy constraints. 可能有重復約束

原因:系統自動判斷 代碼 和 編輯器中可能有重復約束,可能會出錯

Probably at least one of the constraints in the following list is one you don‘t want.

Try this:

(1) look at each constraint and try to figure out which you don‘t expect;

(2) find the code that added the unwanted constraint or constraints and fix it.

(

解決方案:修改某個對象約束的優先級


setValue:forUndefinedKey:]:this class is not key value coding-compliant for the key xxxx

原因:模型的屬性和plist文件不匹配

根本原因:屬性缺失錯誤key後面的XX //找屬性,數據類型,基本數據類型是不是多了*

1.找不到同名的plist數據和模型屬性

改正:修改plist或模型的名稱保持一致

2.模型不是指針類型的寫了*號

改正:修改模型的類型或者去掉*號

原因:xib文件沒有選擇(鏈接)視圖名稱 導致模型給視圖賦值報錯e.g.shopView.shop= shop;

解決方案:修改xib的Custom Class



報錯描述:Failed to instantiate the default view controller for UIMainStoryboardFile ‘Main‘ - perhaps the designated entry point is not set?

報錯原因:沒有設置指向控制器的箭頭 is Inital View Controller

解決方案:屬性頁面 View Controller 設置is Inital View Controller為YES


變量沖突 copyWithZone unrecognized selector sent to instance

報錯描述:-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x7fff21746b20

報錯原因 :屬性和變量名沖突

解決方案:修改屬性或者變量名


壞指針 使用代理方法時EXC_BAD_ACCESS

錯誤描述:

錯誤原因:寫錯了 讓代理執行代理方法前的判斷語句,寫成了執行語句.

if([self.delegateperformSelector:@selector(addVC:andAdditem:)]) {

GLaddItem*additem = [GLaddItemaddItemWithName:self.nameTextF.textandNum:self.tellTextF.text];

[self.delegateaddVC:selfandAdditem:additem];

[self.navigationControllerpopViewControllerAnimated:YES];

}

解決方案:把performSelector方法改成respondsToSelector

if([self.delegaterespondsToSelector:@selector(addVC:andAdditem:)]) {

GLaddItem*additem = [GLaddItemaddItemWithName:self.nameTextF.textandNum:self.tellTextF.text];

[self.delegateaddVC:selfandAdditem:additem];

[self.navigationControllerpopViewControllerAnimated:YES];

}


壞指針 EXC_BAD_ACCESS Conflicting return type in implementation of ‘addItem‘: ‘數據類型x‘ vs ‘返回值‘

錯誤描述: Conflicting return type in implementation of ‘addItem‘: ‘GLaddItem *‘ vs ‘void‘

運行時 , 訪問變量時 , 導致壞指針

錯誤原因: 定義的方法名和變量名重復

解決方案:修改方法名或變量名稱


loaded the ’xxx’ view outlet was not set

錯誤描述‘-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "GLEditController" nib but the view outlet was not set.‘

報錯原因:通過xib描述的控制器沒有連續view

解決方案: 在xib中連接Owner的view


Incompatible pointer to integer conversion assigning to ‘UITableViewCellSeparatorStyle‘ (aka ‘enum UITableViewCellSeparatorStyle‘) from ‘UISwitch *‘

提示 賦值不正確,對象應該是個枚舉值


isEqualToString,length 模型類,模型對象使用混亂

-[GLWine isEqualToString:]

-[GLWine length]: unrecognized selector sent to instance

錯誤原因:賦值了不正確的對象 模型數組裏面是模型類對象,不是模型對象

解決方法:先創建模型類對象,再使用模型對象

GLWine*wine =self.wines[indexPath.row];

cell.imageView.image= [UIImageimageNamed:wine.image];


字典轉模型沒有值,報錯[__NSCFString objectForKeyedSubscript:] [__NSCFDictionary length]

沒有值:

1.控制器重寫模型數組的get方法中首先沒有初始化數組

_wines= [NSMutableArrayarray];沒初始化添加的對象為空null

2[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance

[__NSCFDictionary length]: unrecognized selector sent to instance

Incompatible pointer types assigning to ‘NSString *‘ from ‘NSDictionary *‘

報錯原因:沒有寫完整字典,註意在模型對象中用字典賦值的字典書寫完整性,forin一般是遍歷數組,

解決方法:檢查字典書寫完整性,並根據數據源(plist或網絡)修改

tip提示:若是字典裏dict[@"cars”]字典key輸入不正確,只會導致沒有數據然而不會報錯.


tableView代理對象沒有實現方法

[ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

0.代理對象沒有聲明對應的協議

Assigning to ‘id _Nullable‘ from incompatible type ‘ViewController *const __strong‘self.tableView.dataSource=self;或者拖線給控制器(其他代理對象)

1.代理對象沒有實現必須實現的協議方法1

Method ‘tableView:numberOfRowsInSection:‘ in protocol ‘UITableViewDataSource‘ not implemented

2.代理對象沒有實現必須實現的協議方法2

Method ‘tableView:numberOfRowsInSection:‘ in protocol ‘UITableViewDataSource‘ not implemented-[ViewController tableView:numberOfRowsInSection:]

3.代理對象沒有實現必須實現的協議方法3Method ‘tableView:cellForRowAtIndexPath:‘ declared here

-[UITableView _configureCellForDisplay:forIndexPath:]

解決方法 必須實現:

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView//不實現返回1

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

-(UITableViewCell*)tableView


寫錯標點

報錯: Expected ‘]’ or ‘,’

原因: 1.數組連接符號用錯 解決方案:需要用 , 逗號鏈接

2.數組最後一個元素寫了連接符號 解決方案:去掉最後一個元素後的連接符號

3.Expected ‘;’ after expression 簡寫數組,最後沒有寫分號 解決方案:加上語句結束符號 ;


約束錯誤

Unable to simultaneously satisfy constraints.

Probably at least one of the constraints in the following list is one you don‘t want.

Try this:

(1) look at each constraint and try to figure out which you don‘t expect;

(2) find the code that added the unwanted constraint or constraints and fix it.

無法同時滿足的約束。

可能至少在以下列表中的約束之一是一個你不想要。

試試這個: (1) 看看每個約束和試著去弄了,你不會指望;

(2) 找到添加不必要的約束或限制的代碼並修復它。

錯誤原因1://把A對象的底部等於B右邊,對應連線找不到

make.bottom.equalTo(blueView.right);

錯誤原因2://同一個對象重復寫了同一個約束

make.top.equalTo(blueView.top);

make.top.equalTo(blueView.bottom);


Could not load NIB in bundle with name XXX

原因reason: ‘Could not load NIB in bundle: ‘NSBundle 找不到要讀取的nib

(loaded)‘ with name ‘GLshopView‘‘

解決方案:把xib的名字改成何視圖類名一樣


Auto property synthesis will not synthesize property ‘title‘; it will be implemented by its superclass, use @dynamic to acknowledge intention

錯誤原因:自動屬性合成不會合成屬性title;它將由它的超類,使用承認意圖 @dynamic 執行

UILabel...title

改正:UILabel不要使用title 作為屬性標識符


No visible @interface for ‘NSArray<__kindof UIView *>‘ declares the selector ‘removeLastObject‘

錯誤原因:NSArray是不可變數組 不能使用刪除最後一個元素

解決方案:使用NSMutableArray 或者[self.shoptable.subviews.lastObjectremoveFromSuperview];


-[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]‘

-[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]‘ -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]‘

index 0 beyond bounds for empty array

錯誤原因:數組下標越界了

解決方案:打印檢查數組的個數,並根據需要修改


unrecognized selector sent to instance

原因:調用了一個不存在的方法,方法被刪掉/註釋/名稱修改

解決:認真檢查方法名,使用正確並且存在的方法名


not key value for the key... 多余連線

原因:IBOutlet屬性代碼被刪掉/註釋了,但是屬性連線還在

根本原因:屬性缺失錯誤key後面的XX //找屬性

解決:將storyboard殘留的連線刪掉,或在把線連上


Receiver type ‘NSTextAlignment‘ (aka ‘enum NSTextAlignment‘) is not an Objective-C class

錯誤原因 :is not an Objective-C class屬性返回值是個枚舉,後面寫了個類調用方法

解決方案:直接寫枚舉值

鏈接:https://www.jianshu.com/p/12babc2cc406
來源:簡書

xcode上編譯c語言程序報錯:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)