macos中与fcntl的链接错误

macos中与fcntl的链接错误,macos,gcc,linker,fcntl,Macos,Gcc,Linker,Fcntl,有一个使用fcntl的代码sinppet,但在链接时遇到问题: #include <poll.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #inclu

有一个使用fcntl的代码sinppet,但在链接时遇到问题:

#include <poll.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <fcntl.h>

int main()
{
    struct addrinfo hints, *ai, *cur_ai;
    int port, fd = -1;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    char portstr[10];
    char hostname[] = "www.google.com";
    snprintf(portstr, sizeof(portstr), "%d", port);
    int ret = getaddrinfo(hostname, portstr, &hints, &ai);
    if(ret)
    {
        printf("die");
        return ;
    }
    printf("getaddrinfo !!!");

    cur_ai = ai;
    fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
    fcntl(fd, F_SETFL, fcnt(fd, F_GETFL) | O_NONBLOCK);
    ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);

}
如何将其配置为成功通过编译? 我的GCC版本是:

qty:socket_lab qrtt1$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如果您查看链接器返回的错误,您应该会看到您的问题,在您的代码中,您使用的是
fcnt
,而您的意思很可能是
fcntl
,如果您查看链接器返回的错误,您应该会看到您的问题,在您的代码中,您使用的是
fcnt
,而您最可能的意思是
fcntl

X-Istence,请找出我的打字错误。非常感谢。X-Istence,找出了我的打字错误。非常感谢你。
qty:socket_lab qrtt1$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.