Skip to content

fix: fix build errors with newer GCC and resolve const qualifier mism… - #13

Open
Dirinkbottle wants to merge 2 commits into
NJU-ProjectN:masterfrom
Dirinkbottle:master
Open

fix: fix build errors with newer GCC and resolve const qualifier mism…#13
Dirinkbottle wants to merge 2 commits into
NJU-ProjectN:masterfrom
Dirinkbottle:master

Conversation

@Dirinkbottle

Copy link
Copy Markdown

…atch with newer GCC #12
修复在 x86_64 GCC 16.2.1 20260810 下编译 ARCH=native 时出现的兼容性问题。

  1. 修复 cstring.c 中字符串函数返回值的 const qualifier mismatch,避免新版 GCC 在严格类型检查下触发 -Werror=discarded-qualifiers

  2. 修复项目兼容层与宿主 libc 头文件之间的类型/声明不一致,以及新版 GCC 更严格检查所暴露出的相关编译错误,使 bsp/abstract-machine 下的 make ARCH=native 能正常通过编译。

@KEDIT2007

Copy link
Copy Markdown

我遇到了同样的问题,拉取这个 PR 后 ARCH=native 可以正常编译,但 ARCH=$ISA-nemu 不行。

我的交叉编译依赖 newlib。newlib 的 sys/types.h 在定义 clock_t / time_t 之前就会 #include <sys/select.h>。这个包含会被解析到 RT-Thread 的 sys/select.h,再间接包含 newlib 的 time.h,而此时 clock_t 尚未定义。glibc 没有这个问题。

部分报错:

In file included from .../sys/time.h:18,
                 from .../sys/select.h:17,
                 from .../newlib/include/sys/types.h:50,
                 from .../bsp/abstract-machine/include/extra.h:2,
                 from ./rtconfig.h:3,
                 from .../include/rtthread.h:25,
                 from .../bsp/abstract-machine/src/context.c:3:
.../newlib/include/time.h:56:1: error: unknown type name ‘clock_t’
   56 | clock_t    clock (void);
      | ^~~~~~~

把对 sys/types.h 的包含限制在 native 之后,我这边 nemunative 都能编译:

#ifdef __ISA_NATIVE__
#include <sys/types.h>
/* posix remaps ... */
#else
typedef long suseconds_t;
typedef unsigned long useconds_t;
#endif

@Dirinkbottle

Dirinkbottle commented Aug 16, 2026

Copy link
Copy Markdown
Author
ISA: riscv32 PLATFORM: nemu
- CC /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/devfs/devfs.c
- CC /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c
- CC /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/elmfat/ff.c
- CC /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/elmfat/ffunicode.c
- CC /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c
In file included from /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/libc/compilers/common/include/sys/time.h:18,
                 from /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/libc/compilers/common/include/sys/select.h:17,
                 from /opt/riscv-multilib-all/riscv64-unknown-elf/include/sys/types.h:50,
                 from /opt/riscv-multilib-all/riscv64-unknown-elf/include/sys/_default_fcntl.h:217,
                 from /opt/riscv-multilib-all/riscv64-unknown-elf/include/sys/fcntl.h:3,
                 from /opt/riscv-multilib-all/riscv64-unknown-elf/include/fcntl.h:1,
                 from /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/include/dfs.h:18,
                 from /home/inkbottle/othersrc/ysyx/ysyx-workbench/ics-pa/rt-thread-am/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c:11:
/opt/riscv-multilib-all/riscv64-unknown-elf/include/time.h:56:1: error: unknown type name 'clock_t'
   56 | clock_t    clock (void);
      | ^~~~~~~
/opt/riscv-multilib-all/riscv64-unknown-elf/include/time.h:30:1: note: 'clock_t' is defined in header '<time.h>'; this is probably fixable by adding '#include <time.h>'
   29 | #include <sys/timespec.h>
  +++ |+#include <time.h>
   30 | 

尝试了一下,我这里最后又会回到sys/time.h去找struct timeval. 所以这次我手动补了struct timeval; 不包括完整定义. 并且修改了cstdlib在前面包含完整的stddef.h即可.后面需要完整的timeval再包含sys/time.h 此时time.h需要的类型已经被stddef.h补齐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants