0

我正在尝试在我的 iPhone 应用程序中使用 SmallSockets 来建立与 Windows 主机(服务器)的 TCP 套接字连接。当我编译时,我收到以下错误:

  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 开发的新手,而且对套接字编程非常陌生,所以当涉及到这些错误时,我非常迷茫。任何帮助深表感谢。谢谢!

这是我用来建立连接的代码:

-(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];
}

如果我将整个方法注释掉,我不会收到任何错误。不确定这是否有助于阐明这个问题。

4

1 回答 1

1

终于想通了...我在将库文件添加到项目时没有选择“添加到目标”。/掌脸

于 2012-05-31T19:41:18.990 回答