[UNIX环境高级编程](第三版)中apue.h的问题

编译 gcc -g myls.c 时,报错 ‘找不到头文件 apue.h’
apue.h是作者自己写的一个文件,系统不自带。其中包含了常用的头文件,以及出错处理函数的定义。

需要到 http://www.apuebook.com/code3e.html(这本书的官网) 下载 ‘src.3e.tar.gz’
进行解压(最新版产生的目录apue.3e),并执行安装
tar -zvx -f src.3e.tar.gz
进入目录apue.3e,执行安装
./configure
make
make install

但当执行 make时报错
make[1]: *** [barrier] 错误 1
解决方法:由于执行make时依赖于 libbsd这个库,需要安装 libbsd,
libbsd的官方解释:This library provides useful functions commonly found on BSD systems,
and lacking on others like GNU systems, thus making it easier to port projects with strong BSD origins,
without needing to embed the same code over and over again on each project.
Linux与Unix有一定的差异,libbs库提供了一些 Linux系统中缺少的东西

libbsd库需要到 http://pkgs.org/search/?query=libbsd&type=smart 确定下载的版本,执行安装(yum/apt-get)
或者下载到本地windows系统,通过ftp工具传送到Linux再安装
根据Linux的版本,下载相应的两个安装文件
例如CentOS 6系列/x86_64,需要下载
libbsd-0.6.0-1.el6.art.x86_64.rpm
libbsd-devel-0.6.0-1.el6.art.x86_64.rpm
然后按照顺序 安装即可
yum install libbsd-0.6.0-1.el6.art.x86_64.rpm
yum install libbsd-devel-0.6.0-1.el6.art.x86_64.rpm

再到apue.3e ,执行make、make install
此时会产生静态库文件 libapue.a,也就是最初报错缺少的东西
cp /apue.3e/include/apue.h /usr/include/
cp ./lib/libapue.a /usr/lib

执行编译通过
gcc myls.c -o myls -lapue (编译需要连接静态库)

另分享一个rpm资源的网站,可以搜索linux各个版本的软件资源
http://rpm.pbone.net/ (底部分为4种模式查询)

完!

猜你喜欢

转载自blog.csdn.net/quzery/article/details/89668800
今日推荐