不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2017-10-26 14:10:54  修改时间:2024-04-09 03:31:06  分类:C/C++/Rust  编辑

操作系统:Mac OS X 10.11.5

1、下载书中的源代码:点击下载

2、切换到解压后的目录 unpv13e,先查看下 README,依次执行:

./configure

cd lib
make

cd ../libfree
make

【此处报错】

inet_ntop.c:56:1: error: conflicting types for 'inet_ntop'
inet_ntop(af, src, dst, size)
^
/usr/include/arpa/inet.h:77:13: note: previous declaration is here
const char inet_ntop(int, const void , char , socklen_t);
^
1 error generated.
make: **
[inet_ntop.o] Error 1

提示函数'inet_ntop'重复声明了,其实是 头文件重复包含了。

【解决方法】

找到 inet_ntop.c 文件把 #include <arpa/inet.h> 这行注释掉,重新 make,成功!

3、安装 unp.h 文件及其对应的静态链接库 libunp.a 到 系统目录

cd ..  # 回到主目录

# 修改 unp.h
vim ./lib/unp.h  # 修改 #include "../config.h" 为 #include "config.h"

# 拷贝头文件
sudo cp ./config.h  /usr/local/include
sudo cp ./lib/unp.h  /usr/local/include

# 拷贝库文件
sudo cp ./libunp.a  /usr/local/lib

4、接下来就可以编译书中的一些例子了,可以使用库文件链接 -lunp

 

 

参考:

《UNIX环境高级编程(第3版)》apue.h等源码文件的编译安装

http://www.jianshu.com/p/7e395e4f8515

https://www.cppfans.org/1411.html