函数 err_sys() 定义在哪里? [英] Where is function err_sys() defined?
本文介绍了函数 err_sys() 定义在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此代码中收到与 err_sys()
相关的错误:
I am getting an error related to err_sys()
in this code:
#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()
定义在哪里?
推荐答案
把它放在你的代码之上:
Place this on top of your code:
void err_sys(const char* x)
{
perror(x);
exit(1);
}
perror 在 stdio.h 中定义
perror is defined in stdio.h
err_sys 在 Richard Stevens 的UNIX 网络编程:套接字网络 API"一书中使用.据我所知,这并不常见.
err_sys is used in the book "UNIX Network Programming: The sockets networking API" by Richard Stevens. It's not something common, as far as I know.
修复代码错误
这篇关于函数 err_sys() 定义在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文