Collect2.exe: error: ld returned 1 exit status linking error

Hello Everyone,

I am trying to fix a linking error with platformio. However, I encountered an error below.

Not sure where these errors are coming from. I just used platformio 3 months ago and I am not really an expert in using the tools.

 *  The terminal process "C:\Users\leo_a\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder ProteusBard: C:\Users\leo_a\.platformio\penv\Scripts\platformio.exe run 

Processing megaatmega1280 (platform: atmelavr; board: megaatmega1280; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/megaatmega1280.html
PLATFORM: Atmel AVR (4.0.0) > Arduino Mega or Mega 2560 ATmega1280
HARDWARE: ATMEGA1280 16MHz, 8KB RAM, 124KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr @ 5.1.0
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
Converting DC1902_ProteusBard.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SdFat @ 2.1.2
|   |-- SPI @ 1.0
|-- genieArduino @ 1.5.3
|-- ElapsedMillis
|-- EEPROM @ 2.0
|-- SPI @ 1.0
|-- Firmata
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\megaatmega1280\src\DC1902_ProteusBard.ino.cpp.o
Linking .pio\build\megaatmega1280\firmware.elf
.pio\build\megaatmega1280\src\datalogger.cpp.o (symbol from plugin): In function `portB':
.pio\build\megaatmega1280\src\datalogger.cpp.o (symbol from plugin): In function `portB':
(.text+0x0): multiple definition of `__vector_9'
.pio\build\megaatmega1280\src\DC1902_ProteusBard.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio\build\megaatmega1280\src\datalogger.cpp.o (symbol from plugin): In function `portB':
(.text+0x0): multiple definition of `__vector_10'
.pio\build\megaatmega1280\src\DC1902_ProteusBard.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio\build\megaatmega1280\src\datalogger.cpp.o (symbol from plugin): In function `portB':
(.text+0x0): multiple definition of `__vector_11'
.pio\build\megaatmega1280\src\DC1902_ProteusBard.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio\build\megaatmega1280\src\datalogger.cpp.o (symbol from plugin): In function `portB':
(.text+0x0): multiple definition of `HandleInterruptRadCount()'
.pio\build\megaatmega1280\src\DC1902_ProteusBard.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega1280\firmware.elf] Error 1

Hi @laxentiq ,

I edited your post to wrap the compiler output in code blocks, it reads better and there are certain characters that vanish if this is not done. :wink:

You appear to have multiple definitions of some functions, possibly interrupt handlers – _vector_9, __vector_10 and __vector_11. You also seem to have at least two versions of the HandleInterruptRadCount function.

Looking at the vector ones, I’ve seen this on an Arduino Uno project of mine. I was using an interrupt handler for a specific interrupt, but that was already in use by the Arduino Language internally – to handle Millis() and Micros(). If you define this handler in Arduino code, you get similar error messages. The compiler spits out these “vector” names rather than what you have called your ISR(yada_yada). The g++ compiler counts vectors from zero, the data sheet from 1, so don;t be fooled. Your actual interrupt vectors are 10, 11 and 12. Looking at the data sheet for the ATMega1280, these appear to be PCINT0, PCINT1 and PCINT2 – are you using pin change interrupts?

As the Arduino Language doesn’t (usually) use those three, I suspect you have somehow got more than one source file in your project which has the same/similar code within and in which handlers for those three interrupts have been defined? This might also help explain why HandleInterruptRadCount is defined more than once too.

PlatformIo will compile every *.c and *.cpp source file that it finds, so check for duplicates, temporary files you didn;t intend to include in the project etc.

Hopefully, this will help.

Cheers,
Norm.

Hi Norm,

Thanks for giving me the idea. Yes, you are right there are some duplicate variables in the files, and have already fixed them. It both solved the vector and HandleInterrupt.

Thanks a lot.

Cheers,
laxentiq

1 Like