Help building in debug for platformio

tacertain

Member
Hey all -

I'm hoping this is a simple config change that I just have not been able to uncover: I'm trying to make a debug build in platformio, and I'm getting the following error:

Code:
.pio\build\teensy41\src\main.cpp.o: in function `__static_initialization_and_destruction_0(int, int)':
./src/main.cpp:300: undefined reference to `vtable for USBHIDInput'

The code builds and links fine for the normal build. I found this thread that seems to indicate it's maybe a problem with optimization levels in debug builds, but it wasn't clear to me what the fix was. Does anybody have any hints for me on what to try?

Thanks.

Andrew
 
Well, I just declared the the methods in the base class that don't have a default implementation to be pure virtual. That at least got it to link. We'll see if I get any crashes!
 
Well, I just declared the the methods in the base class that don't have a default implementation to be pure virtual. That at least got it to link. We'll see if I get any crashes!
That rings a bell...

It was fixed in the repository last year, there just hasn't been an official Teensyduino release since then. Recommend you either use the beta packages from the announcements forum or the code from the git repos directly if you want the latest changes.
 
Thanks! Any idea why it works on the regular build and not in debug? I guess I could track it down if I get bored with other stuff!
 
In the regular build there's never any access to the vtable of USBHIDInput because it's not used directly (only as a base class for others to derive from) so it is never referenced. But debug disables optimizations and also enables extra features that require the vtables of underlying classes to be present, so all the virtual functions in it need to be either implemented or declared as pure virtual.
 
I'm running into seemingly-random occurrences of undefined reference to 'vtable for FlexIO2VGA' when adding or removing functions that seem quite mundane and operating on local vars only. I tried various optimizations, didn't change. I'll go look at the annoucements.

EDIT: I installed beta 1.60 and still have the problem.

Code:
/home/tomj/Bin/arduino-1.8.19/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /tmp/arduino_build_505776/sketch/fZ80.5.ino.cpp.o: in function `FlexIO2VGA::~FlexIO2VGA()':
/home/tomj/Projects/Arduino/libraries/SR-VGA_4BIT_T4-MINIMAL/src/VGA_4bit_T4.h:190: undefined reference to `vtable for FlexIO2VGA'
/home/tomj/Bin/arduino-1.8.19/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /tmp/arduino_build_505776/sketch/fZ80.5.ino.cpp.o: in function `_GLOBAL__sub_I_vga4bit':
/home/tomj/Projects/Arduino/fZ80.5/fZ80.5.ino:1545: undefined reference to `vtable for FlexIO2VGA'
collect2: error: ld returned 1 exit status
 
Last edited:
Ahh. It's in VGA4bit, built on FlexIO2VGA. There are some virtuals (write). I'm not clear on what virtuals are; I'll go rtfm and report back.
 
Ahh. It's in VGA4bit, built on FlexIO2VGA. There are some virtuals (write). I'm not clear on what virtuals are; I'll go rtfm and report back.
I just went through and checked. The only two virtuals are:
Code:
  virtual size_t write(const char *buffer, size_t size);
  virtual size_t write(uint8_t c);
I had forgotten about them. You will find the most of the available display drivers and the print library have the write function defined as virtual. The write function is used in such things as "Serial.print", "Serial.println", "Serial.printf", "vga4bit.print" etc... It's been a while since I looked at virtual functions and how vtables are used :)
 
Ahh... OK that's a feature of C++ I've never used, wasn't thinking of those extentions to the Serial object. I had modified write() to take the x and y args directly, inlined pixel writing, and did a number of unrelated things to speed performance and cut memory use (I've used the entire megabyte), having completely forgot about how other objects can be used to extend Serial.

I'll move my mods elsewhere. It was laziness on my part (existing code making write() calls, I'll just change those) and leave the virtuals in place.

I'm still cleaning up and testing, I'll tell you about it all soon.
 
Back
Top