Can't use attachInterrupt and Serial when using avr_debug

I have started to code my project and I find very limited info on debugging so I moved to the platform.io IDE for my Arduino Uno. I am using an avr-debugger library but my project fails to build and gives the multiple definitions of __vector_18 or in attachInterrupt multiple definition of __vector_1 and im not sure why this is happening. All my code/build files on github at

Hey, while I might not be able to help you (I am somewhat a newbie myself in regards to PlatformIO and C++), I am sure a proper log of your pio run command would help.

In my case (in MacOS 14.1.2, CLion 2023, PlatformIO 6.1.11) it looks something like that whenever I build the code using platformio-core (I believe it’s what it’s using under the hood):

/opt/homebrew/bin/pio run -e zeroUSB
Processing zeroUSB (platform: atmelsam; board: zeroUSB; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/zeroUSB.html
PLATFORM: Atmel SAM (8.2.0) > Arduino Zero (USB Native Port)
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES: 
....
Compiling .pio/build/zeroUSB/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/zeroUSB/libFrameworkArduino.a
Indexing .pio/build/zeroUSB/libFrameworkArduino.a
Linking .pio/build/zeroUSB/firmware.elf
Checking size .pio/build/zeroUSB/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.6% (used 3796 bytes from 32768 bytes)
Flash: [=         ]  12.8% (used 33532 bytes from 262144 bytes)
Building .pio/build/zeroUSB/firmware.bin
========================= [SUCCESS] Took 2.32 seconds =========================

I am asking, because in https://github.com/dixit9123/IO_expander/tree/master/.pio/build/uno I do see firmware.hex and firmware.elf files, which leads me to believe, that it was able to build something.

Please copy the full log of your pio run command and please state which machine / OS you are on and what tools (and versions thereof) you use.

Processing uno (platform: atmelavr; board: uno; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (5.0.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.2.0
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf      
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...    
Dependency Graph
|-- avr-debugger @ 1.5.0
|-- MCP23017 @ 2.0.0    
|-- Wire @ 1.0
Building in release mode
Linking .pio\build\uno\firmware.elf
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_2'
avr8-stub.c.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
================================================================================== [FAILED] Took 1.11 seconds ==================================================================================
 *  The terminal process "C:\Users\Ashu\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

The problem seems to be with me having the attachInterrupt function in my code, but I make sure the other interrupt pin is free for the debugger to use.

The program will build if I comment out the attachInterrupt function, but the interrupt is what I want to test.

You have to observe its documented limitations properly. Using avr-debugger in its standard configuration means that the Serial object is used to transport GDB requests and responses, and so using Serial in the debugged program itself is not possible by default, the same as using attachInterrupt().

See https://github.com/jdolinay/avr_debug/blob/master/doc/avr_debug.pdf

See https://github.com/dixit9123/IO_expander/pull/1 on how I would handle that.