How to redirect STDIO to USB Serial?

With an older version of Particle firmware, I was able to successfully redirect standard out and standard in to use the USB serial port.

Here’s a snippet of my retarget code:

#define SERIAL USBSerial1
#define SERIAL Serial
#error "No compatible platform"

extern "C" void retarget_init()
  // Initialize UART
  // done in application.c

  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);


extern "C" int fgetc(FILE * p_file)
  uint8_t input = -1;
  if (SERIAL.available() > 0) {
    input =;

    return input;

extern "C" int fputc(int ch, FILE * p_file)


  return ch;

Then I use putchar and fgetc in my simple shell console module to read and write to the targeted UART.
With newer Particle IOT firmware that introduces “dynalib” feature, I am no longer able to link my image due to the stdio (repeated) definitions in hal_dynalib_posix_syscall.h.
I’ve browsed the dynalib code for a bit but it is not clear to me how this organized.

What is the “proper” way to retarget STDIO to the USB serial port?