
是的,我说的unix编程三件套如图所示,如果有正在看这三本书之一的朋友,欢迎阅读本文章,希望能对你有帮助,该文章帮你总结好了《unix环境高级编程》的apue.h,《卷二unix进程间通信》的unpipc.h,《卷一套接字联网API》的unp.h及其库的编译安装。注:本平台为Deepin20.4,不出意外该教程适用于所有linux发行版,毕竟不涉及到系统什么层面。
1、《unix环境高级编程》
源码下载
代码比较古老,可能会编译不过,可以用大神修改好的源码直接编译即可,无需折腾。
linux安装apue库
可能需要的库:sudo apt install libbsd-dev
2、《卷二:进程间通信》第二版
unpipc库源码
注:有两个文件,下载好后解压第一个即可,我也不知道为何有两个,似乎是分压的吧
现在就是安装,我之所以写这篇文章,是因为后面这两本书执行./configure之后都有一个config.h头文件,最后复制到系统/usr/local/include目录下unix编程环境,会冲突且两文件不兼容。具体编译过程请看源码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 /* */
^~~~~~~~
../config.h:56:26: error: two or more data types in declaration specifiers
#define uint8_t unsigned char /* */
^~~~
../config.h:57:18: error: two or more data types in declaration specifiers
#define uint16_t unsigned short /* */
^~~~~~~~
../config.h:57:27: error: two or more data types in declaration specifiers
#define uint16_t unsigned short /* */
^~~~~
../config.h:58:18: error: two or more data types in declaration specifiers
#define uint32_t unsigned int /* */
^~~~~~~~
../config.h:58:27: error: two or more data types in declaration specifiers
#define uint32_t unsigned int /* */
^~~
make: *** [<内置>:daemon_inetd.o] 错误 1
打开../config.h 注释掉这三行
// #define uint8_t unsigned char /* */
// #define uint16_t unsigned short /* */
// #define uint32_t unsigned int /* */
同时将该文件重命名configunpipc.h,复制到/usr/local/include下
修改源码里面lib下的unpipc.h文件,如图改好后,重新make编译,最后生成libunpipc.a文件再复制到/usr/local/lib下,进程间通信这本书的库就安装好了
//把原来的#include "../config.h"改为
#include "configunpipc.h"
3、《卷一:套接字联网API》第三版
库源码
最后时套接字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), mino
unpipc.h编译出错解决方法_miuwen_新浪博客unpipc.h编译出错解决方法_miuwen_新浪博客,miuwen,
UNIX网络编程 卷1:套接字联网API -- 编译 - JUST DO IT ~ - BlogJava
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|