samedi 25 juillet 2020

Simple Arduino PlatformIO C++11 project has undefined reference to default constructor during linking stage (but intellisense detects no errors)

I've been scouring the internet trying to find a solution and done a ton of tinkering myself, but at this point, I've lost all my hair and feel no closer to solving this problem.

The intellisense in VSCode with Platformio extension is able to auto complete the constructors from /lib/SelectWheel/SelectWheel.h, but it seems like the build linker can't find the header and/or cpp file. Why would the intellisense and build process disagree? How can I fix this?

Here's the error:

Linking .pio\build\megaatmega2560\firmware.elf
C:\Users\matth\AppData\Local\Temp\cclHZ2N6.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_selectWheel':
<artificial>:(.text.startup+0xf6): undefined reference to `SelectWheel::SelectWheel()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1

Here's the terminal output for pio run -t clean and platformio run --verbose: https://pastebin.com/xn862p00

Here's the project structure:

Hydro9000
| -- .pio
| -- .vscode
| -- include
|     | -- Adafruit_BusIO
|     | -- Adafruit_EPD
|     | -- Adafruit_GFX_Library
|     | -- Adafruit_SSD1306
|     | -- ArduinoSTL
| -- lib
|     | -- SelectWheel
|     |    | -- SelectWheel.h
|     |    | -- SelectWheel.cpp
| -- src
|    | -- main.cpp
| -- platformio.ini

Here's platformio.ini

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

Here's /src/main.cpp

#include <Arduino.h>
#include "SelectWheel/SelectWheel.h"

SelectWheel* selectWheel = new SelectWheel();

void setup() {}
void loop() {}

Here's /lib/SelectWheel/SelectWheel.h

#ifndef SelectWheel_h
#define SelectWheel_h

#include "Arduino.h"

class SelectWheel {
    private:
        int pinA, pinB;
        
    public:
        SelectWheel();
        SelectWheel(int, int);
};

#endif

Here's /lib/SelectWheel/SelectWheel.cpp

#include "SelectWheel.h"

SelectWheel::SelectWheel() {}
SelectWheel::SelectWheel(int pinA, int pinB) {
    this->pinA = pinA;
    this->pinB = pinB;
    pinMode(this->pinA, INPUT);
    pinMode(this->pinB, INPUT);
}

Let me know if there is any additional information I can supply to help as I've already tried a bunch of ways to fix this.

I am using...

  • VSCode v1.47.2
  • PlatformIO IDE Extension (platformio.platformio-ide) v1.10.0
  • Microsoft C/C++ Extension (ms-vscode.cpptools) v0.29.0

Aucun commentaire:

Enregistrer un commentaire