今天编译 linux 内核遇上坑了,求解答

2016-04-15 14:33:19 +08:00
 Bryan0Z

系统是 ubuntu14.04 ,内核是 3.13.0-24-generic ,编译过程基本是照着这个教程做的: http://www.franksthinktank.com/howto/addsyscall/ 然后编译时各种报语法错误,手工改了一个还会有另一个文件报错:

include/uapi/linux/random.h:37:1: error: expected ‘=’, ‘,’, ‘;’, ‘ asm ’ or ‘attribute’ before ‘ struct ’

我从官网下的内核好吗,打开源文件一看,虽然我 C 语言差,但是我还是能看出来那里本来就不需要符号吧

最神奇的是 2 个星期前,我做过一次完全一样的实验,那次什么问题都没有,是 ubuntu 在这两个星期内更新了编译器还是怎么回事= =

最后附报错的其中一个文件内容:

/*
 * include/linux/random.h
 *
 * Include file for the random number generator.
 */

#ifndef _UAPI_LINUX_RANDOM_H
#define _UAPI_LINUX_RANDOM_H

#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/irqnr.h>

/* ioctl()'s for the random number generator */

/* Get the entropy count. */
#define RNDGETENTCNT	_IOR( 'R', 0x00, int )

/* Add to (or subtract from) the entropy count.  (Superuser only.) */
#define RNDADDTOENTCNT	_IOW( 'R', 0x01, int )

/* Get the contents of the entropy pool.  (Superuser only.) */
#define RNDGETPOOL	_IOR( 'R', 0x02, int [2] )

/* 
 * Write bytes into the entropy pool and add to the entropy count.
 * (Superuser only.)
 */
#define RNDADDENTROPY	_IOW( 'R', 0x03, int [2] )

/* Clear entropy count to 0.  (Superuser only.) */
#define RNDZAPENTCNT	_IO( 'R', 0x04 )

/* Clear the entropy pool and associated counters.  (Superuser only.) */
#define RNDCLEARPOOL	_IO( 'R', 0x06 )

struct rand_pool_info {
	int	entropy_count;
	int	buf_size;
	__u32	buf[0];
};

#endif /* _UAPI_LINUX_RANDOM_H */
3376 次点击
所在节点    Linux
5 条回复
bp0
2016-04-15 15:31:03 +08:00
gcc 的错误提示不友好,说 struct 前面需要 attribute ,其实你应该找包含了 random.h 的地方。看在这些地方之前是否有语句缺少了“,“或者”;”
jackal
2016-04-15 15:50:42 +08:00
@bp0 说的很对。

另外, 请逐行检查自己添加和修改的代码,除了一些语句可能少了,; 也有可能是自己加入的一些#define #ifdef 等宏开关, 并没有正确的用#endif 来结尾

帮助调试的话, 用 gcc -E 来处理预编译文件,看文件的详细情况,查找对应报错地方的前后代码是否有错。
Bryan0Z
2016-04-15 17:19:17 +08:00
@jackal
@bp0
关键是报错的文件都是我没改过的…这我就比较郁闷了,官网下的源代码, 2 个星期前同样的代码可以编译,现在就不行了
bp0
2016-04-15 17:56:17 +08:00
都说了不是 random.h 文件的问题,是包含这个头文件的其他源文件或者头文件的问题。

所以,当出现这个问题时,你需要看正在编译的源文件是什么。
Bryan0Z
2016-04-15 18:02:01 +08:00
@bp0 噗,谢谢,我再去检查一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/271325

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX