0

I am trying some library files for esp8266. I created hpp and .cpp files. But i try to compile program i got this error on VSCode. collect2.exe: error: ld returned 1 exit status *** [.pio\build\huzzah\firmware.elf] Error 1 I put files in src folder but still got this. What are points that i missed?

Building in release mode
Linking .pio\build\huzzah\firmware.elf
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::Neotimer()':
main.cpp:(.text._ZN8NeotimerC2Ev+0x0): multiple definition of `Neotimer::Neotimer()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerC2Ev+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::Neotimer()':
main.cpp:(.text._ZN8NeotimerC2Ev+0x0): multiple definition of `Neotimer::Neotimer()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerC2Ev+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::Neotimer(unsigned long)':
main.cpp:(.text._ZN8NeotimerC2Em+0x0): multiple definition of `Neotimer::Neotimer(unsigned long)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerC2Em+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::Neotimer(unsigned long)':
main.cpp:(.text._ZN8NeotimerC2Em+0x0): multiple definition of `Neotimer::Neotimer(unsigned long)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerC2Em+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::~Neotimer()':
main.cpp:(.text._ZN8NeotimerD2Ev+0x0): multiple definition of `Neotimer::~Neotimer()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerD2Ev+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::~Neotimer()':
main.cpp:(.text._ZN8NeotimerD2Ev+0x0): multiple definition of `Neotimer::~Neotimer()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8NeotimerD2Ev+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::init()':
main.cpp:(.text._ZN8Neotimer4initEv+0x0): multiple definition of `Neotimer::init()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer4initEv+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::repeatReset()':
main.cpp:(.text._ZN8Neotimer11repeatResetEv+0x0): multiple definition of `Neotimer::repeatReset()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer11repeatResetEv+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::done()':
main.cpp:(.text._ZN8Neotimer4doneEv+0x4): multiple definition of `Neotimer::done()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer4doneEv+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::set(unsigned long)':
main.cpp:(.text._ZN8Neotimer3setEm+0x0): multiple definition of `Neotimer::set(unsigned long)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer3setEm+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::get()':
main.cpp:(.text._ZN8Neotimer3getEv+0x0): multiple definition of `Neotimer::get()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer3getEv+0x0): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::stop()':
main.cpp:(.text._ZN8Neotimer4stopEv+0x4): multiple definition of `Neotimer::stop()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer4stopEv+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::reset()':
main.cpp:(.text._ZN8Neotimer5resetEv+0x8): multiple definition of `Neotimer::reset()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer5resetEv+0x8): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::repeat()':
main.cpp:(.text._ZN8Neotimer6repeatEv+0xc): multiple definition of `Neotimer::repeat()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer6repeatEv+0xc): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::repeat(int)':
main.cpp:(.text._ZN8Neotimer6repeatEi+0x8): multiple definition of `Neotimer::repeat(int)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer6repeatEi+0x8): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::repeat(int, unsigned long)':
main.cpp:(.text._ZN8Neotimer6repeatEim+0x4): multiple definition of `Neotimer::repeat(int, unsigned long)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer6repeatEim+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::start()':
main.cpp:(.text._ZN8Neotimer5startEv+0x4): multiple definition of `Neotimer::start()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer5startEv+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::debounce(bool)':
main.cpp:(.text._ZN8Neotimer8debounceEb+0x8): multiple definition of `Neotimer::debounce(bool)'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer8debounceEb+0x8): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::restart()':
main.cpp:(.text._ZN8Neotimer7restartEv+0x4): multiple definition of `Neotimer::restart()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer7restartEv+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::waiting()':
main.cpp:(.text._ZN8Neotimer7waitingEv+0x4): multiple definition of `Neotimer::waiting()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer7waitingEv+0x4): first defined here
c:/users/dogan/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o: in function `Neotimer::started()':
main.cpp:(.text._ZN8Neotimer7startedEv+0x0): multiple definition of `Neotimer::started()'; .pio\build\huzzah\src\communication.cpp.o:communication.cpp:(.text._ZN8Neotimer7startedEv+0x0): first defined here

Sorry, i am new on stackexchange community so i can do basic mistakes about usage.

Now, i am adding my main.cpp,communication.cpp and communication.h files. As i said before, i didnt included neotimer and deleted. I used to add this library to my project, PIO library interface. I am thinking this problem coming from this. Great thanks for your patient and advises.

communication.cpp:

#include "communication.h"
#include "database.h"
#include "management.h"
#include "wifi.h"


String GetCommand(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++)
   {
    if (data.charAt(i) == separator || i == maxIndex) 
    {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void checkStream(WiFiServer tcpServer,WiFiClient tcpClient, Neotimer timer,boolean pulseCheck)
{


 // WiFiClient _tcpClient;
  tcpClient.setTimeout(200);
  tcpClient  = tcpServer.available();

  if(tcpClient && tcpClient.connected())
  {
    Serial.println("Timer Off");
    timer.stop();
    String requestStr = tcpClient.readStringUntil('\r');
      if(requestStr.length()>=8)
      {
        tcpClient.print(ParseStream(requestStr));
        pulseCheck = false;
        delay(3000);
         String requestSplitStr = GetCommand(requestStr, ' ', 0);
         if(requestSplitStr == "ayg_set_modem_info")
         {
          Serial.println("Device is going to sleep now!");
          Sleep();
         }
      }  
  }
  else
  { 
    return;
  }
}

String ParseStream(String content)
{
  String requestSplitStr = GetCommand(content, ' ', 0);
  if(requestSplitStr == "ayg_set_modem_info")
  {
    String ssid = GetCommand(content, ' ', 1);
    String pass = GetCommand(content, ' ', 2); 
    Serial.println("SSID,PASS TAKING");
    delay(200); 
    ClearEP();
    boolean resSsid = WriteEPSsid(ssid);
    boolean resPass = WriteEPPass(pass);
    Aprint("SSID: "+ReadEPSsid());
    Aprint("Pass: "+ReadEPPass()); 
    //_tcpClient.flush();
    if(resPass)
    {
      if(STATest())
      {
        return JsonResult("true");

      }
      else
      {
        return JsonResult("false");
      }

    }
    else
    {
      return JsonResult("false");
    }

  }

  else if(requestSplitStr == "ayg_get_vbatt")
  {
    return JsonResult(GetBattery());
   // _tcpClient.flush();
   // _tcpClient.stop();
  }

communication.h

#ifndef communication_h
#define communication_h
#if ARDUINO > 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <neotimer.h>
#include "ArduinoJson.h"

//VARIABLES


    String GetCommand(String data, char seperator, int index);
    String ParseStream(String content);
    void checkStream(WiFiServer tcpServer,WiFiClient tcpClient, Neotimer timer,boolean pulseCheck);
    String JsonResult(String result);


#endif

main.cpp:

#include <stdlib.h>
#include <HX711.h>
#include <Arduino.h>
#include <ESP8266WebServer.h>

#include <string.h>
#include "communication.h"
#include <management.h>
#include <wifi.h>
#include <database.h>






#define DOUT 13 // D7
#define SCK 15 // D8
#define led1 5 // D1- Color?
#define led2 4 // D2-Color?
#define led3 0 // D3-Color?
#define led4 2 // D4 Color?
#define led5 14 // D5 Color_?
#define button 12 //Button-D5
#define VERSION "1.0"
#define CALIBRATIONWEIGHT 5.0
#define LPG  12.2

struct rst_info *rtc_info = system_get_rst_info();
ADC_MODE(ADC_VCC);
WiFiServer _tcpServer(41400);
WiFiClient _tcpClient;
//HTTPClient http;
HX711 scale;


/*Scale Values*/
float tareValFromclient;
float calibration_factor = 26845.0;
float grossWeight;
char sGrossWeight[10];
int ledPercentage;
/*Sleep Values*/
bool sleepPulseCheck=false;


/*Timers and Intervals*/
/*const unsigned long sleepInterval = 200000; // Seconds to sleep
const unsigned long scaleInterval = 2000; // Interval for scaling tank
const unsigned long ledInterval = 200;
Neotimer sleepTimer(sleepInterval);
Neotimer scaleTimer(scaleInterval);
Neotimer ledTimer(ledInterval);*/

#pragma region PROTOYPES
/*PROTOTYPES*/
void Initialize();
String checkTankTare();
void powerUpScale();
void powerDownScale();
bool Tare();
void getGrossWeight(float *fGross, char*sGross);
String getDeviceTare();
float calculateFirstNetWeight();
float getNetWeight();
int calculatePercentage();
void ledDrivePercentage(int percentage);
String calibrateScale();
#pragma endregion

/*---------------------------------------*/

void setup() {
  ESP.eraseConfig();
  Initialize();
  Serial.println("started");
}

void loop() {
  //Serial.printf("connected:%d\n", WiFi.softAPgetStationNum()); // bağlı client sayısı
 calibrateScale();
// checkStream(_tcpServer,_tcpClient,/*sleepTimer*/sleepPulseCheck);
 ledDrivePercentage(calculatePercentage());
 WriteEPGross(sGrossWeight);




 if(sleepPulseCheck == false)
 {
   sleepPulseCheck = true;
  // sleepTimer.start();
   Serial.println("Sleep Fired");


 }
}
  • 1
    the neotimer library is wrong. it can't be included in more then one file – Juraj Jan 11 at 18:33
  • I deleted all includes and only included at communication.cpp but still getting this error – Dogan Cignakli Jan 11 at 18:37
  • 1
    one half of your previous comment can't be true – Juraj Jan 11 at 18:43
  • I did it but still same – Dogan Cignakli Jan 11 at 19:38
  • We cannot tell you more, because you didn't give us enough information. Juraj exactly wrote, what the compilation output, that you posted, tells us: The neotimer library was defined multiple times. You should show us your code and link to the used libraries. Then we can check in your code, where the problem is (curing the disease instead of trying to cure the symptom). – chrisl Jan 12 at 0:20
1

The problem stems from the fact that the author of the Neotimer "library" defined the methods in the header file, see neotimer.h.

If you include this header in more than 1 source of your project, you will get these "multiple definition" errors.

To solve this issue you have (at least) these options:

  1. Make Neotimer a correct library with separated header and source files. Compile the source into a library file. Since I'm not experienced with Arduino I don't know how other libraries do this.
    • Disadvantage: You're messing with 3rd-party code. Commonly this is discouraged. You'll have to maintain your copy of the library yourself, which renders some benefits of using libraries void.
  2. Don't include neotimer.h in a header file of yours, include it only in one of your source files. If you need some declaration like the Neotimer type in other modules, add a forward declaration but don't include its header file.
  3. Use another library that is better implemented.

You might say that you include neotimer.h in only one module. That's wrong. You included it in your own header file communication.h, which you include in both source files. This way it sneaks into both modules. You can't do anything about this with preprocessor "magic" because both modules are compiled independently from each other.


This is the class declaration of Neotimer as of 2020-01-12 18:40 UTC. Use as much as you need from it as forward declaration. You could even put this in decent header file.

class Neotimer{
    public:
    //Methods
    Neotimer();
    Neotimer(unsigned long _t);      //Constructor
    ~Neotimer();            //Destructor

    void init();            //Initializations
    boolean done();         //Indicates time has elapsed
    boolean repeat(int times);
    boolean repeat(int times, unsigned long _t);
    boolean repeat();
    void repeatReset();
    boolean waiting();          // Indicates timer is started but not finished
    boolean started();          // Indicates timer has started
    void start();           //Starts a timer
    unsigned long stop();           //Stops a timer and returns elapsed time
    void restart();
    void reset();           //Resets timer to zero
    void set(unsigned long t);
    unsigned long get();
    boolean debounce(boolean signal);
    int repetitions = NEOTIMER_UNLIMITED;

    private:

    struct myTimer{
        unsigned long time;
        unsigned long last;
        boolean done;
        boolean started;
    };

    struct myTimer _timer;
    boolean _waiting;
};
|improve this answer|||||
  • Can you explain forward declaration? How can i do that? I did search on internet and it is like a function prototyping. – Dogan Cignakli Jan 12 at 17:37
  • 1
    Well, I'm tempted to send you back to your C++ book. ;-) But my edit might help you, though. – the busybee Jan 12 at 18:41
  • Thanks for the great help. I am new on C++ and embedded systems. I am try to deep dive and try write modular codes. But i got your temp and will check c++ rules :) – Dogan Cignakli Jan 12 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.