Ubuntu 20.10编译APUE第三版源码

第一个问题:

/usr/bin/ld: /tmp/ccmTGRc3.o: in function `main':
devrdev.c:(.text+0xc5): undefined reference to `minor'
/usr/bin/ld: devrdev.c:(.text+0xdb): undefined reference to `major'
/usr/bin/ld: devrdev.c:(.text+0x128): undefined reference to `minor'
/usr/bin/ld: devrdev.c:(.text+0x13e): undefined reference to `major'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:18:devrdev] 错误 1
make[1]: 离开目录“/home/cxs/code/apue.3e/filedir”
make: *** [Makefile:6:all] 错误 1

要加上:

#include <sys/sysmacros.h>

第二个问题:

gcc -ansi -I../include -Wall -DLINUX -D_GNU_SOURCE  buf.c -o buf  -L../lib -lapue 
buf.c: In function ‘is_linebuffered’:
buf.c:90:15: error: ‘FILE’ {aka ‘struct _IO_FILE’} has no member named ‘__pad’; did you mean ‘__pad5’?
   90 | #define _flag __pad[4]
      |               ^~~~~
buf.c:104:13: note: in expansion of macro ‘_flag’
  104 |  return(fp->_flag & _IOLBF);
      |             ^~~~~
buf.c:105:1: warning: control reaches end of non-void function [-Wreturn-type]
  105 | }
      | ^
make[1]: *** [Makefile:16:buf] 错误 1
make[1]: 离开目录“/home/cxs/code/apue.3e/stdio”

解决办法:将./stdio/buf.c文件的

#ifdef _LP64
#define _flag __pad[4]
#define _ptr __pad[1]
#define _base __pad[2]
#endif

接着,将flag改成flags

int
is_unbuffered(FILE *fp)
{
    return(fp->_flags & _IONBF);
}

int
is_linebuffered(FILE *fp)
{
	return(fp->_flag & _IOLBF);
}

int buffer_size(FILE *fp)函数要做相应改变

int
buffer_size(FILE *fp)
{
#ifdef _LP64
    return(fp->_IO_buf_end - fp->_IO_buf_base);
#else
	return(BUFSIZ);	/* just a guess */
#endif
}

lbsd问题依旧存在,解决方法没变。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值