Getting Error 1 when building [Solved]

Hey evreyone.
I think I need some help from You guys.
I’m doing a weather station project based on a Arduino Mega 2560 and a ethernet shield (v1).
I also added a LCD display controlled by a keypad.

The thing is when I’m Trying to build the project, I get the error.

collect2.exe: error: ld returned 1 exit status
*** [.pioenvs\megaatmega2560\firmware.elf] Error 1

I put all sources of my project on Github: https://github.com/Guisch/Station-Meteo
Heres all the log when building

Summary
[03/27/18 10:47:29] Processing megaatmega2560 (platform: atmelavr; lib_deps: Ethernet, EthernetUdp, SD, SPI, Arduino, Wire, Keypad, LiquidCrystal; board: megaatmega2560; framework: arduino)

Library Storage: C:\Users\ghcas\AppData\Roaming\SPB_16.6\Documents\PlatformIO\Projects\Station meteo\.piolibdeps
LibraryManager: Installing id=872
Ethernet @ 1.1.2 is already installed
Looking for EthernetUdp library in registry
Warning! Library `{'requirements': None, 'name': 'EthernetUdp'}` has not been found in PlatformIO Registry.
You can ignore this message, if `{'requirements': None, 'name': 'EthernetUdp'}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
LibraryManager: Installing id=161
SD @ 1a24a9486d is already installed
Looking for SPI library in registry
Warning! Library `{'requirements': None, 'name': 'SPI'}` has not been found in PlatformIO Registry.
You can ignore this message, if `{'requirements': None, 'name': 'SPI'}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
Looking for Arduino library in registry
arduino

=======
#ID: 2171
arduino library for mbed



Keywords: arduino

Compatible frameworks: mbed

Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500

Authors: SE HUI PARK



Arduino

=======
#ID: 2172
Library to allow the use of Arduino specific language with the mbed



Keywords: mbeduino, arduino

Compatible frameworks: mbed

Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500

Authors: Chris Dick



Arduino

=======
#ID: 3194
Arduino functions millis, micros and eventually some more to come



Keywords: micros, millis, arduino

Compatible frameworks: mbed

Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500

Authors: Eduardo de Mier



Found: platformio .org/lib/show/2171/arduino
LibraryManager: Installing id=2171
arduino @ 3b83fc30bb is already installed
Looking for Wire library in registry
Warning! Library `{'requirements': None, 'name': 'Wire'}` has not been found in PlatformIO Registry.
You can ignore this message, if `{'requirements': None, 'name': 'Wire'}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
LibraryManager: Installing id=165
Keypad @ 3.1.1 is already installed
LibraryManager: Installing id=136
LiquidCrystal @ 1.3.4 is already installed
PLATFORM: Atmel AVR > Arduino Mega or Mega 2560 ATmega2560 (Mega 2560)
SYSTEM: ATMEGA2560 16MHz 8KB RAM (248KB Flash)
Library Dependency Finder -> bit .ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(light)
Collected 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Ethernet> v1.1.2 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\Documents\PlatformIO\Projects\Station meteo\.piolibdeps\Ethernet_ID872)
|   |-- <SPI> v1.0 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|-- <SD> (C:\Users\ghcas\AppData\Roaming\SPB_16.6\Documents\PlatformIO\Projects\Station meteo\.piolibdeps\SD_ID161)
|   |-- <SPI> v1.0 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|-- <SPI> v1.0 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|-- <Wire> v1.0 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\Wire)
|-- <Keypad> v3.1.1 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\Documents\PlatformIO\Projects\Station meteo\.piolibdeps\Keypad_ID165)
|-- <LiquidCrystal> v1.3.4 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\Documents\PlatformIO\Projects\Station meteo\.piolibdeps\LiquidCrystal_ID136)
|   |-- <Wire> v1.0 (C:\Users\ghcas\AppData\Roaming\SPB_16.6\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\Wire)
avr-g++ -o .pioenvs\megaatmega2560\firmware.elf -Os -mmcu=atmega2560 -Wl,--gc-sections -flto -fuse-linker-plugin .pioenvs\megaatmega2560\src\date.cpp.o .pioenvs\megaatmega2560\src\enregistrement.cpp.o .pioenvs\megaatmega2560\src\main.cpp.o .pioenvs\megaatmega2560\src\menu.cpp.o .pioenvs\megaatmega2560\src\serveur.cpp.o -L.pioenvs\megaatmega2560 -Wl,--start-group .pioenvs\megaatmega2560\lib5db\libSPI.a .pioenvs\megaatmega2560\liba0f\libEthernet_ID872.a .pioenvs\megaatmega2560\libe7d\libSD_ID161.a .pioenvs\megaatmega2560\lib854\libWire.a .pioenvs\megaatmega2560\lib381\libKeypad_ID165.a .pioenvs\megaatmega2560\libed3\libLiquidCrystal_ID136.a .pioenvs\megaatmega2560\libFrameworkArduinoVariant.a .pioenvs\megaatmega2560\libFrameworkArduino.a -lm -Wl,--end-group

Thanks !

Your problem is not with PIO but with your code. You are having a header file which instantiates VARIABLES in every CPP file it is included, thus duplicating variables like crazy.

Look at your enregistrement.h file:


#ifndef ENREGISTREMENT
#define ENREGISTREMENT

/* .. */ 

File fichierSD;

unsigned long position_fin_fichier;

float compteur;

float tempMinObs;
unsigned long tempMinTime;
float tempMaxObs;
unsigned long tempMaxTime;
float tempMoyObs;
float temperature
float tempSomme;

Now every time your #include "enregistrement.h that file (e.g. in main.cpp and in enregistrement.cpp), your file gets a copy of these variables.

What you most probably want is that these are global variables which only exist once. For that, your header file must declare each variable to be extern. You then have to define these variables once in one CPP file.

So, e.g. in enregistrement.h the line File fichierSD; becomes extern File fichierSD;, while in some .cpp file (say, e.g. enregistrement.cpp), you place File fichierSD; as a global variable on top of the file. Do that with all your variables until the linker doesn’t complain about duplicate definitions anymore.

2 Likes

Indeed ! That worked for me. Thanks a lot ! :slight_smile: