加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

函数err_sys()在哪里定义?

发布时间:2020-12-16 05:30:38 所属栏目:百科 来源:网络整理
导读:我在这段代码中收到与err_sys()相关的错误: #include stdio.h#include sys/socket.h#include netinet/in.hint main(){ int sockfd; if ((sockfd=socket(AF_INET,SOCK_STREAM,0))0) err_sys("can't create socket"); close(sockfd); return 0;} 我收到链接器
我在这段代码中收到与err_sys()相关的错误:
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main()
{
    int sockfd;

    if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
        err_sys("can't create socket");

    close(sockfd);
    return 0;
}

我收到链接器错误:

/tmp/cciuUVhz.o: In function `main':
getsockopt.c:(.text+0x38): undefined reference to `err_sys'
collect2: ld returned 1 exit status

函数err_sys()在哪里定义?

解决方法

将其放在您的代码之上:
void err_sys(const char* x) 
{ 
    perror(x); 
    exit(1); 
}

perror是在stdio.h中定义的

err_sys在Richard Stevens的书“UNIX网络编程:套接字网络API”中使用.据我所知,这不是常见的事情.

编辑:固定代码错误

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读