Linker error: multiple definitions of __vector_18

Hi,
I’m trying to get the library ‘avr_debugger’ by jdolinay working on my arduino Uno. I can remember (or i hope so), that it has worked for me in the past, so i think it should be fixable.

For more detail, I’m getting this error from the linker, when i try to build/upload the [env:uno_debug] enviroment:

Linking .pio\build\uno_debug\firmware.elf
HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_18'
avr8-stub.c.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno_debug\firmware.elf] Error 1
================================================================================= [FAILED] Took 13.61 seconds =================================================================================

The whole log (pio run --verbose > compile.log 2>&1 --environment uno_debug) is found here on GitHub (from a later run, the error is from the build command without verbose).

Here is the relevant portions of my PlatformIO.ini:

[platformio]
default_envs = uno

[env]
framework = arduino
monitor_speed = 115200
monitor_filters = send_on_enter
monitor_echo = yes
lib_deps =
    fastled/FastLED@^3.9.9
    z3t0/IRremote@^4.4.1

[env:uno_debug]
platform = atmelavr
board = uno
build_flags =
    -D DEBUG_ATMEGA328P
debug_tool = avr-stub
debug_port = COM3
lib_deps =
    ${env.lib_deps}
    jdolinay/avr-debugger@^1.5

The whole project is available on GitHub:
theMoonlitWolf/Floating-Island-2

I have tried cleaning, searched for the definition in avr8-stub.cpp (and didn’t find it), and the --undefined flag for the linker and nothing worked.

I would still like to be able to use Serial, so can I (safely) ignore this error somehow?

Does anyone have any idea what could fix this?

Thank you very much,
theMoonlitWolf

avr-stub, on the Uno, uses the only one available Hardware Serial fully for itself, full stop. Your sketch can’t use Serial. Please see

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

Possible ways of working around this is:

  • creating a new SoftwareSerial DebugSerial object on different pins, and printing to that
  • sending the seiral output through avr-stub to GDB (messages are only visible during a debug session)

Ok, thank you, I can work with that. Like, when #ifdef DEBUG_ATMEGA328P, use debug_message instead of Serial.print.