C++ 20 support on the Teensy

iontodirel

New member
I was able to successfully use C++ 20, by modifying the teensy\hardware\avr\1.59.0\boards.txt.

However, I noticed I am getting some linker errors about definitions not found for few C functions.

I fixed this using the following:

#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>

void _exit(int status) { while (1) {} }
int _close(int file) { return -1; }
int _fstat(int file, struct stat *st) { st->st_mode = S_IFCHR; return 0; }
int _isatty(int file) { return 1; }
int _lseek(int file, int ptr, int dir) { return 0; }
int _read(int file, char *ptr, int len) { return 0; }
int _write(int file, char *ptr, int len) { return len; }
int _kill(int pid, int sig) { return -1; }
int _getpid(void) { return 1; }
int _sbrk(int incr) { return -1; }

Not sure why these functions are needed, or what are they referenced by, but this was the biggest issue for me when targeting C++20.

One last minor thing, sees like the toolset does not support UTF-8 source files with a BOM.
 
At least some of those functions are implemented in Teensyduino so I'm not sure why they would be missing symbols. Especially _sbrk, without a proper implementation of that you won't be able to do anything that involves dynamic memory allocation.
 
Did you change to use -std=c++20 or -std=gnu++20? If the former, try the latter. I’m able to compile Teensy projects just fine as C++20 projects.
 
Back
Top