书:
在unpbook 官网下载了源码,在Mac OS上make了里面的源码,我做的步骤:
1)chmod u+x configure
./configure
2)cd lib
make
3)cd ../libfree
make (报错了)
4)cd ../libgai
make (报错了)
然后试着去gcc一个TCP echo回文Server程序,然后一堆报错
#include "unp.h"
int
main(int argc, char **argv)
{
int listenfd, connfd;
pid_t childpid;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;
void sig_chld(int);
listenfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
Listen(listenfd, LISTENQ);
Signal(SIGCHLD, sig_chld);
for ( ; ; ) {
clilen = sizeof(cliaddr);
if ( (connfd = accept(listenfd, (SA *) &cliaddr, &clilen)) < 0) {
if (errno == EINTR)
continue; /* back to for() */
else
err_sys("accept error");
}
if ( (childpid = Fork()) == 0) { /* child process */
Close(listenfd); /* close listening socket */
str_echo(connfd); /* process the request */
exit(0);
}
Close(connfd); /* parent closes connected socket */
}
}
}
稍微gcc下,报一堆错误
Undefined symbols for architecture x86_64:
"_Bind", referenced from:
_main in tcpserv03-11de6f.o
"_Close", referenced from:
_main in tcpserv03-11de6f.o
"_Fork", referenced from:
_main in tcpserv03-11de6f.o
"_Listen", referenced from:
_main in tcpserv03-11de6f.o
"_Signal", referenced from:
_main in tcpserv03-11de6f.o
"_Socket", referenced from:
_main in tcpserv03-11de6f.o
"_err_sys", referenced from:
_main in tcpserv03-11de6f.o
"_sig_chld", referenced from:
_main in tcpserv03-11de6f.o
"_str_echo", referenced from:
_main in tcpserv03-11de6f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.