2012-05-31 71 views
0

我想在我的iPhone應用程序中使用SmallSockets來建立到Windows主機(服務器)的TCP套接字連接。當我編譯,我得到以下錯誤:SmallSockets與iPhone應用程序的鏈接器錯誤

Undefined symbols for architecture i386: 
    "_OBJC_CLASS_$_Socket", referenced from: 
    objc-class-ref in SmallSocketsTestViewController.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

具體而言,在紅,有下面幾行:

"_OBJC_CLASS_$_Socket", referenced from: 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我是新來的iOS開發和很新的Socket編程,所以我當談到這些錯誤時,我很失落。任何幫助深表感謝。謝謝!

這裏是我用來建立連接的代碼:

-(IBAction)btnConnect:(id)sender 
{ 
    Socket *socket; 
    int port = 11005; 
    NSString *host = @"19.5.8.63"; 

    socket = [Socket socket]; 

    @try 
    { 
     NSMutableData *data; 
     [socket connectToHostName:host port:port]; 
     [socket readData:data]; 
    // [socket writeString:@"Hello World!"]; 

    //** Connection was successful **// 
    //[socket retain]; // Must retain if want to use out of this action block. 
    } 
    @catch (NSException* exception) 
    { 
     NSString *errMsg = [NSString stringWithFormat:@"%@",[exception reason]]; 
     NSLog(errMsg); 
     socket = nil; 
    } 

    //** Disconnect **// 
    [socket close]; 
} 

如果我評論這整個方法的時候,我沒有錯誤。不知道這是否有助於澄清這個問題。

回答

1

終於搞清楚了......當我將庫文件添加到項目中時,我沒有選擇「添加到目標」。/facepalm

+0

我看你正在進步,對你有好處;) – antf

+0

Yessir。非常感謝StackOverflow社區中的好人:) – Skizz