Skip to content

Fix clock_t issue when compiling with newlib#9

Open
Chen-Yuanmeng wants to merge 1 commit into
NJU-ProjectN:masterfrom
Chen-Yuanmeng:fix-1
Open

Fix clock_t issue when compiling with newlib#9
Chen-Yuanmeng wants to merge 1 commit into
NJU-ProjectN:masterfrom
Chen-Yuanmeng:fix-1

Conversation

@Chen-Yuanmeng

Copy link
Copy Markdown

Using newlib cross compilers (i.e. riscv64-unknown-elf-), the compiler gives the following error:

+ CC src/context.c
In file included from /home/kali/Desktop/ysyx-workbench/rt-thread-am/components/libc/compilers/common/include/sys/time.h:18,
                 from /home/kali/Desktop/ysyx-workbench/rt-thread-am/components/libc/compilers/common/include/sys/select.h:17,
                 from /opt/riscv/riscv64-unknown-elf/include/sys/types.h:50,
                 from /home/kali/Desktop/ysyx-workbench/rt-thread-am/bsp/abstract-machine/include/extra.h:3,
                 from ./rtconfig.h:3,
                 from /home/kali/Desktop/ysyx-workbench/rt-thread-am/include/rtthread.h:25,
                 from /home/kali/Desktop/ysyx-workbench/rt-thread-am/bsp/abstract-machine/src/context.c:3:
/opt/riscv/riscv64-unknown-elf/include/time.h:56:1: error: unknown type name 'clock_t'
   56 | clock_t    clock (void);
      | ^~~~~~~
/opt/riscv/riscv64-unknown-elf/include/time.h:33:1: note: 'clock_t' is defined in header '<time.h>'; this is probably fixable by adding '#include <time.h>'
   32 | #include <sys/_locale.h>
  +++ |+#include <time.h>
   33 | #endif
make: *** [/home/kali/Desktop/ysyx-workbench/abstract-machine/Makefile:101: /home/kali/Desktop/ysyx-workbench/rt-thread-am/bsp/abstract-machine/build/riscv64-nemu/src/context.o] Error 1

This is caused by Newlib's <sys/types.h> which includes <sys/select.h> before it defines clock_t.

Copilot AI review requested due to automatic review settings July 19, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a build failure with newlib-based cross compilers where clock_t is not yet defined when newlib’s <sys/types.h> pulls in <sys/select.h>, causing RT-Thread’s wrapper include chain to trigger <time.h> too early.

Changes:

  • Adds a compiler/include-state conditional at the top of RT-Thread’s sys/select.h wrapper to fall back to the toolchain’s <sys/select.h> via #include_next during the problematic newlib include sequence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +22
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && defined(_SYS_TYPES_H) && \
!defined(__clock_t_defined) && !defined(_CLOCK_T_DECLARED)
#include_next <sys/select.h>
#else
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