undefined reference to gdb_init


New member

I'm trying to get a simple program running on a Teensy 4.1. It's basically a stub to generate a PWM signal that I can look at on an oscilloscope. I type in a number from zero to 9 to get a more positive PWM signal out. Yup, it's a crap little program.

#include "teensydebug.h"
#pragma GCC optimize ("O0")

const int analogOutPin = 5;  // Analog output pin that the LED is attached to

int incomingByte = 0;  // value read from the pot

void setup() {
  // initialize serial communications at 9600 bps:
   while (!SerialUSB1) {}    // Wait for Debugger connect
   debug.begin(SerialUSB1);  // Start Debug Serial e.g. COM11
//  debug.begin(SerialUSB) ;
  pinMode (analogOutPin,OUTPUT) ;

void loop() {
if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    incomingByte = incomingByte - '0' ;
    incomingByte = 25 * incomingByte ;//Gross simplification

  // change the analog out value:
  analogWrite(analogOutPin, incomingByte);

  // print the results to the Serial Monitor:
  Serial.print("Output = ");
  Serial.print("Control byte = ");


It runs fine from the Arduino IDE and I can test that the output is correct with the oscilloscope. but I want to have the debugger running in Visual Micro. However the program fails with a Collect2 error when I compile it in Visual Micro.

ld.exe: TeensyDebug.cpp.o: in function Debug::write(unsigned char const*, unsigned int)
TeensyDebug.h:154: undefined reference to gdb_out_write(unsigned char const*, unsigned int)

ld.exe: TeensyDebug.cpp.o: in function debug_begin(Stream*)

Error linking for board Teensy 4.1 (teensy41)
Debug build failed for project 'AnalogInOutSerial'
teensydebug.cpp:1222: undefined reference to gdb_init(Stream*)

Can somebody tell me what I haven't installed properly? I've read a lot of stuff that hasn't helped!