2012-05-30 62 views
2

我寫了一個簡單的函數,傳入編譯器但不傳遞鏈接器。iOS未定義鏈接器ld錯誤

任何想法爲什麼?

- (BOOL) connectedToWifi 
{ 

    CFArrayRef myArray = CNCopySupportedInterfaces(); 
    // Get the dictionary containing the captive network infomation 
    CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); 

    NSLog(@"Information of the network we're connected to: %@", captiveNtwrkDict); 

    NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict; 
    NSString* ssid = [dict objectForKey:@"SSID"]; 

    if ([ssid rangeOfString:@"WXYZ"].location == NSNotFound || ssid == NULL) 
    { 
     return false; 
    } 
    else 
    { 
     return true; 
    } 
} 

這是我的錯誤:

Undefined symbols for architecture i386: 
    "_CNCopySupportedInterfaces", referenced from: 
     -[miApp_funcs connectedToWifi] in miApp_funcs.o 
    "_CNCopyCurrentNetworkInfo", referenced from: 
     -[miApp_funcs connectedToWifi] in miApp_funcs.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
+1

聽起來像你缺少必需的庫或框架,嘗試添加SystemConfiguration框架到您的目標。 – danielbeard

+0

新手在這裏,我如何用獅子上最新的Xcode做到這一點? – user848106

+0

在側欄中單擊您的項目 - >鏈接框架和庫 - > + - >,然後選擇SystemConfiguration框架 – danielbeard

回答

3

你要鏈接到,並#import <SystemConfiguration/SystemConfiguration.h>,有機會獲得圈養網(CN)類和函數。

3

下面是步驟 -

1)點擊項目Navigator區域

2)選擇 '目標' 選項卡

3)點擊 '構建階段'

4)選擇「鏈接二進制文件庫'

5)然後,您可以在區域底部看到'+'按鈕。 您現在可以添加所需的SystemConfiguration框架。

#import <SystemConfiguration/SystemConfiguration.h> 
相關問題