Undefined reference

seaboat_wang seaboat_wang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在学习Computer System这本书
看到第十二章, 按照书上的代码敲了一个Web Server出来

#include "csapp.h"

void echo(int connfd);

int main( int argc, char **argv)
{
int listenfd, connfd, port, clientlen;
struct sockaddr_in clientaddr;
struct hostent *hp;
char *haddrp;

if(argc != 2)
{
fprintf(stderr, "Usage: %s <port> \n", argv[0]);
exit(0);
}
port = atoi(argv[1]);

listenfd = Open_listenfd(port);
while(1)
{
clientlen = sizeof(clientaddr);
connfd = accept(listenfd, (SA *)&clientaddr, &clientlen);

hp = Gethostbyaddr( (const char *)&clientaddr.sin_addr.s_addr, sizeof(clientaddr.sin_addr.s_addr), AF_INET);
haddrp = inet_ntoa(clientaddr.sin_addr);
printf("Server connected to %s (%s)\n", hp->h_name, haddrp);

echo(connfd);
Close(connfd);

}
exit(0);
}

void echo(int connfd)
{
size_t n;
char buf[MAXLINE];
rio_t rio;

Rio_readinitb(&rio,connfd);
while( (n = Rio_readlineb(&rio, buf, MAXLINE)) != 0)
{
printf("Server received %d bytes\n", n);
Rio_writen(connfd, buf, n);
}
}





在Ubuntu 64bit下面
gcc -Wall server.c -o server

编译器报错:
undefined reference to "Open_listenfd"
undefined reference to "Gethostbyaddr"
undefined reference to "Close"

undefined reference to "Rio_readinitb"
undefined reference to "Rio_writen"
undefined reference to "Rio_readlineb"


头文件 csapp.h我是从教材的官网上下载的
我也看过了, 上面这些“undefined”的函数, 在头文件里面也有。

不明白为什么编译器报错, 望指教!

谢谢!
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
seaboat_wang
C语言 70,040 成员 243,237 内容