APUE编译问题

本文解决一些APUE一书中例子编译过程中的问题

OS: ubuntu 12.04

OS: mac os 10.7.4

问题

Undefined symbols for architecture x86_64:"_CMSG_LEN", referenced from:_recv_fd in libapue.a(recvfd.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

解决

在include/apue.h中增加

#if defined(SOLARIS)
#define _XOPEN_SOURCE   500 /* Single UNIX Specification, Version 2  for Solaris 9 */
#define CMSG_LEN(x) _CMSG_DATA_ALIGN(sizeof(struct cmsghdr)+(x))
#elif defined(MACOS)  /*新增行*/
#elif !defined(BSD)
#define _XOPEN_SOURCE   600 /* Single UNIX Specification, Version 3 */
#endif