GCC无法编译正确的代码

时间:2014-10-18 22:00:59

标签: c gcc

我尝试使用 Ubicom IP7k 处理器为我的旧路由器编译 uClibc 0.9.33.2 。由于GCC和uClibc都没有正式支持它的架构,我必须自己移植并使用来自处理器供应商的GCC(ubicom32-uclinux-gcc (GCC) 4.4.1 20100320 (stable))的修改版本。一切都很好,直到GCC给我一个奇怪的错误。

  CC libc/sysdeps/linux/common/fstatat.os
In file included from libc/sysdeps/linux/common/xstatconv.h:26,
                 from libc/sysdeps/linux/common/fstatat.c:11:
./include/bits/kernel_stat.h:25: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token
./include/bits/kernel_stat.h:52: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token
make: *** [libc/sysdeps/linux/common/fstatat.os] Error 1

kernel_stat.h:

#ifndef _BITS_STAT_STRUCT_H
#define _BITS_STAT_STRUCT_H

#ifndef _LIBC
#error bits/kernel_stat.h is for internal uClibc use only!
#endif

/* This file provides whatever this particular arch's kernel thinks 
 * struct kernel_stat should look like...  It turns out each arch has a 
 * different opinion on the subject... */

struct kernel_stat {
    unsigned short st_dev;
    unsigned short __pad1;
    unsigned long st_ino;
    unsigned short st_mode;
    unsigned short st_nlink;
    unsigned short st_uid;
    unsigned short st_gid;
    unsigned short st_rdev;
    unsigned short __pad2;
    unsigned long  st_size;
    unsigned long  st_blksize;
    unsigned long  st_blocks;
    unsigned long  st_atime;            <-- error occurs here
    unsigned long  __unused1;
    unsigned long  st_mtime;
    unsigned long  __unused2;
    unsigned long  st_ctime;
    unsigned long  __unused3;
    unsigned long  __unused4;
    unsigned long  __unused5;
};

struct kernel_stat64 {
    unsigned char   __pad0[6];
    unsigned short  st_dev;
    unsigned char   __pad1[4];
#define _HAVE_STAT64___ST_INO
    unsigned long   __st_ino;
    unsigned int    st_mode;
    unsigned int    st_nlink;
    unsigned long   st_uid;
    unsigned long   st_gid;
    unsigned char   __pad2[6];
    unsigned short  st_rdev;
    unsigned char   __pad3[4];
    long long   st_size;
    unsigned long   st_blksize;
    unsigned long   st_blocks;  /* Number 512-byte blocks allocated. */
    unsigned long   __pad4;     /* future possible st_blocks high bits */
    unsigned long   st_atime;           <-- and here
    unsigned long   __pad5;
    unsigned long   st_mtime;
    unsigned long   __pad6;
    unsigned long   st_ctime;
    unsigned long   __pad7;     /* will be high 32 bits of ctime someday */
    unsigned long long  st_ino;
};

#endif  /*  _BITS_STAT_STRUCT_H */

这里到底出了什么问题,有没有办法解决这个问题而不必更新GCC?

1 个答案:

答案 0 :(得分:4)

st_atime等不能是struct stat的成员。相反,它们是扩展为st_atim.tv_sec等的宏(注意缺少最终e),而st_atim等是类型为struct timespec的成员。内核有这个错误,只是在struct stat概念中重新创建相同的布局,但你必须以对用户空间正确的方式进行。