Unix 编程三件套环境搭建

是的,我说的unix编程三件套如图所示,如果有正在看这三本书之一的朋友,欢迎阅读本文章,希望能对你有帮助,该文章帮你总结好了《unix环境高级编程》的apue.h,《卷二unix进程间通信》的unpipc.h,《卷一套接字联网API》的unp.h及其库的编译安装。 注:本平台为Deepin20.4,不出意外该教程适用于所有linux发行版,毕竟不涉及到系统什么层面。

1、《unix环境高级编程》

源码下载http://www.apuebook.com/code3e.html

代码比较古老,可能会编译不过,可以用大神修改好的源码直接编译即可,无需折腾。 

linux安装apue库https://blog.csdn.net/ninesnow_c/article/details/107428736

可能需要的库:sudo apt install libbsd-dev

2、《卷二:进程间通信》第二版

unpipc库源码https://www.ituring.com.cn/book/156

   

注:有两个文件,下载好后解压第一个即可 ,我也不知道为何有两个,似乎是分压的吧

 现在就是安装,我之所以写这篇文章,是因为后面这两本书执行./configure之后都有一个config.h头文件,最后复制到系统/usr/local/include目录下,会冲突且两文件不兼容。具体编译过程请看源码READEME


chmod +x ./configure #先给configure赋予执行权限
    
./configure    # try to figure out all implementation differences

cd lib         # build the basic library that all programs need

make           # use "gmake" everywhere on BSD/OS systems

 如果这样报错,

gcc -g -O2 -D_REENTRANT -Wall -D_POSIX_PTHREAD_SEMANTICS   -c -o daemon_inetd.o daemon_inetd.c
In file included from unpipc.h:7,
                 from daemon_inetd.c:1:
../config.h:56:17: error: two or more data types in declaration specifiers
 #define uint8_t unsigned char    /* <sys/types.h> */
                 ^~~~~~~~
../config.h:56:26: error: two or more data types in declaration specifiers
 #define uint8_t unsigned char    /* <sys/types.h> */
                          ^~~~
../config.h:57:18: error: two or more data types in declaration specifiers
 #define uint16_t unsigned short    /* <sys/types.h> */
                  ^~~~~~~~
../config.h:57:27: error: two or more data types in declaration specifiers
 #define uint16_t unsigned short    /* <sys/types.h> */
                           ^~~~~
../config.h:58:18: error: two or more data types in declaration specifiers
 #define uint32_t unsigned int    /* <sys/types.h> */
                  ^~~~~~~~
../config.h:58:27: error: two or more data types in declaration specifiers
 #define uint32_t unsigned int    /* <sys/types.h> */
                           ^~~
make: *** [<内置>:daemon_inetd.o] 错误 1

 打开../config.h 注释掉这三行

// #define	uint8_t unsigned char				/* <sys/types.h> */
// #define	uint16_t unsigned short				/* <sys/types.h> */
// #define	uint32_t unsigned int				/* <sys/types.h> */

 同时将该文件重命名configunpipc.h,复制到/usr/local/include下

修改源码里面lib下的unpipc.h文件,如图改好后,重新make编译,最后生成libunpipc.a文件再复制到/usr/local/lib下,进程间通信这本书的库就安装好了

//把原来的#include "../config.h"改为

#include	"configunpipc.h"

 3、《卷一:套接字联网API》第三版

库源码https://www.ituring.com.cn/book/164最后时套接字API,下载源码解压、在终端进入源码解压后的目录,编译如下,详情请看README

chmod +x ./configure

./configure    # try to figure out all implementation differences

#当前目录也是会自动生成一个config.h,同样重命名为configunp.h
mv config.h configunp.h

#把configunp.h复制到/usr/local/include
sudo cp configunp.h /usr/local/include

cd lib         # build the basic library that all programs need

#修改unp.h中 #include "../config.h" 为#include "configunp.h"

make           # use "gmake" everywhere on BSD/OS systems

cd ../libfree  # continue building the basic library

make

 进入libfree编译时若报错如下,修改inet_ntop.c 中如图报错地方

gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o in_cksum.o in_cksum.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o inet_ntop.o inet_ntop.c
inet_ntop.c: In function ‘inet_ntop’:
inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype
  size_t size;
         ^~~~
In file included from inet_ntop.c:27:
/usr/include/arpa/inet.h:64:20: error: prototype declaration
 extern const char *inet_ntop (int __af, const void *__restrict __cp,
                    ^~~~~~~~~
make: *** [<内置>:inet_ntop.o] 错误 1
/*inet_ntop.c文件 第60行,如下修改*/
const char *
inet_ntop(af, src, dst, size)
	int af;
	const void *src;
	char *dst;
	socklen_t size; //原来是size_t size;需改为socklen_t size;
{
	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
	default:
		errno = EAFNOSUPPORT;
		return (NULL);
	}
	/* NOTREACHED */
}

修改好后再次make编译,最后把源码目录下生成的libunp.a复制到/usr/local/lib,unix三剑客库文件就安装完成了

吐血经历,一定注意,一定注意不要把这三个头文件或其中任意两个头文件混在一个项目里面,头文件之间有冲突,就像这样!

 

 

 

最后感谢各位大神linux安装apue库 (UNIX环境高级编程)_ninesnow_c的博客-CSDN博客_apue linux在学unix高级变成环境。之前在虚拟机上已经编译过一次了。这次就记录下编译中的问题吧。因为apue项目过老了,出点问题也正常。undefined reference to `minor’首先是这个,先上错误代码devrdev.c: 在函数‘main’中:devrdev.c:19:25: 警告:隐式声明函数‘major’ [-Wimplicit-function-declaration] 19 | printf("dev = %d/%d", major(buf.st_dev), minohttps://blog.csdn.net/ninesnow_c/article/details/107428736

unpipc.h编译出错解决方法_miuwen_新浪博客unpipc.h编译出错解决方法_miuwen_新浪博客,miuwen,http://blog.sina.com.cn/s/blog_9f3f01ad0101icxs.html

UNIX网络编程 卷1:套接字联网API -- 编译 - JUST DO IT ~ - BlogJavahttp://www.blogjava.net/gddg/archive/2015/05/07/424930.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值