《UNIX环境高级编程》中apue.h的问题与《unix网络编程》中unp.h的问题

apue解决方法:

运行程序清单1-1(列出一个目录中的所有文件)

 

提示 "错误:apue.h:没有那个文件或目录".

很是受打击,果断google解决之。

apue.h是作者自定义的一个头文件,包括程序所需的常用头文件及出错处理函数。所以因该将它放入系统头文件中(Linux下是 /usr/include),这样gcc编译器就可以找到它了。

http://www.apuebook.com/下载src.tar.gz包,然后解压至电脑中的某个目录,比如我的是在/unix下
复制代码
user@user-desktop:~$ sudo tar xzf src.tar.gz
复制代码
进入解压目录 apue.2e, 修改 Make.defines.linux 中的 WKDIR =/home/xxx/apue.2e,为 WKDIR =/unix/apue.2e
进入 std目录 ,修改 linux.mk ,将里面的nawk全部改为awk。

复制apue.h和error.c
 将apue.h和error.c两个文件copy到/usr/include 目录下。(apue.h位于 your_apue_path/inlcude ; error.c位于your_apue_path/lib )
 以我的路径为例:
    
复制代码
 user@user-desktop:/usr/include$ cp /unix/apue.2e/inlcude/apue.h apue.h
 user@user-desktop:/usr/include$ cp /unix/apue.2e/lib/error.c error.c (实现apue.h中的出错处理函数)
复制代码

修改apue.h
       在最后一行#endif  前面添加一行 #include "error.c"

这样就OK了。


以上是gcc编译器正常使用的方法,如果在交叉编译器中也要使用以上两个文件的话则将以上两个文件复制到arm-linux-gcc下的include目录下即可

unp.h解决方法:
刚开始学习《Unix网络编程》,输入第一个程序后,遇到各种错误,先将解决方案记录如下。

遇到的第一个错误是:没有找到头文件“unp.h”,该头文件是作者自己写的,并不包含在/usr/include中,这时需要到网上下载unpv13e.tar.gz到某一目录。具体操作:

mkdir /home/yourname/download   %创建存放压缩文件的目录

tar -xzvf unpv13e.tar.gz                  %解压

ls -al                                                %查看该目录下的文件

cd   unpv13e                                   %进入unpv13e 

cat README                                   %查看README文件,其中有具体的安装信息,按照操作即可

QUICK AND DIRTY
===============

Execute the following from the src/ directory:

    ./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

    cd ../libfree  # continue building the basic library
    make

    cd ../libroute # only if your system supports 4.4BSD style routing sockets
    make           # only if your system supports 4.4BSD style routing sockets

    cd ../libxti   # only if your system supports XTI
    make           # only if your system supports XTI

    cd ../intro    # build and test a basic client program
    make daytimetcpcli
    ./daytimetcpcli 127.0.0.1

If all that works, you're all set to start compiling individual programs.

然后,复制unp.h和config.h到/usr/include
cp libunp.a /usr/lib
cp libunp.a /usr/lib64/
cd /lib
cp unp.h /usr/include
cp config.h /usr/include

最后,修改unp.h中的#include "../config.h"为#include "./config.h"。
以上是第一个错误,下面的错误是:
undefined reference to 'err_quit'
undefined reference to 'err_sys'
这也是由于,意思是未定义的声明,也就是说这些函数没有实现,这时候在网上找的 自定义错误处理函数myerr.h

因为error.c 在apue的解决中已经存在/usr/include下,而error.c 需要用到apue的东西,所以在unp.h后面将apue.h包含进来即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值