您的位置:首页 > 产品设计 > UI/UE

Mac下编译"Unix环境高级编程"的apue.h的错误解决

2016-06-26 00:27 585 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: