Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Bryan0Z
V2EX  ›  Linux

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

  •  
  •   Bryan0Z · Apr 15, 2016 · 3864 views
    This topic created in 3688 days ago, the information mentioned may be changed or developed.

    系统是 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 */
    
    5 replies    2016-04-15 18:02:01 +08:00
    bp0
        1
    bp0  
       Apr 15, 2016
    gcc 的错误提示不友好,说 struct 前面需要 attribute ,其实你应该找包含了 random.h 的地方。看在这些地方之前是否有语句缺少了“,“或者”;”
    jackal
        2
    jackal  
       Apr 15, 2016
    @bp0 说的很对。

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

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

    所以,当出现这个问题时,你需要看正在编译的源文件是什么。
    Bryan0Z
        5
    Bryan0Z  
    OP
       Apr 15, 2016 via Android
    @bp0 噗,谢谢,我再去检查一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1463 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 16:53 · PVG 00:53 · LAX 09:53 · JFK 12:53
    ♥ Do have faith in what you're doing.