1. 首先在这里下载代码文件.
2. 根据解压之后README里面所述To build the source, edit the Make.defines.* file for your system and set WKDIR to the pathname of the tree containing the source code.修改Make.defines.macos文件内容,把第六行WKDIR后面的内容改为你的apue.h的解压路径.
3. 这时候先别急着make, 因为你make了会遇到一个"_CMSG_LEN"错误, 如下图:
继续看README里面If you are running on a system other than FreeBSD, Linux, Mac OS X, or Solaris, you'll need to modify the makefiles to include the settings for your system. Also, you'll probably need to modify the source code to get it to build on a different operating system.
也就是说我们需要自己改改代码, 打开apue的include文件夹编辑其中的apue.h我们可以看到_CMSG_LEN_其实是有定义的,只不过在条件编译的时候每判断出Mac OS X而已, 依葫芦画瓢, 在第八行之后加入一下代码:
#elif defined(MACOS)
#define CMSG_LEN(x) _CMSG_DATA_ALIGN(sizeof(struct cmsghdr)+(x))
Ok自此可以正常编译了. 如果之前你不慎先make了, 那么你需要先make clean之后在make.
本文介绍了解决apue.h在不同操作系统上编译时出现的问题,包括如何正确设置WKDIR路径,以及如何修正_CMSG_LEN宏定义,确保源代码能够顺利编译。

1353

被折叠的 条评论
为什么被折叠?



