Undefined reference to `HdCrtlr'?

Good morning,

I am currently in the process of porting a part of the OnStep project (Arduino) to PlatformIO [ESP32 Arduino Framework). Compiling the whole thing works, but the linker doesn’t link it. In the arduino IDE you can compile the code. In Platformio I get the error

.pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x14): undefined reference to `HdCrtlr’

In the original project, both the declaration and the definition of some objects were together in one .h file. I split this and created a .cpp file with definition for each object, which is in the src directory. In the include\ diirectory the .h files with the declaration are located. The corresponding Smartcontroller.h file is also #include into the .cpp.

main.cpp

#include <Arduino.h>
#include “main.h”

//…
SmartHandController HdCtrlr; //Create HdCtrlr

void setup(void)
{
//the next line gives the error
HdCrtlr.setup(Version, pin, active, SERIAL_BAUD_DEFAULT, static_castSmartHandController::OLED(DISPLAY_OLED));
//some other code here
}

void loop()
{
HdCrtlr.update(); //Smarthandcontroller
}

main.h

#pragma once

#include <Arduino.h>
#include <string.h>
#include <limits.h>
#include <WiFi.h>
#include <WiFiClient.h> //ab hier klasssiche Severvariante
#include <WebServer.h>
#include <WiFiAP.h>
#include <EEPROM.h>
#include “EEPROMFunc.h”
#include <Preferences.h>
#include “Constants.h”
#include “Languages.h”
#include “Config.h”
#include “Language.h”
#include “Pinmap.h”
#include “Globals.h”
#include “SmartController.h” //here the declaration of class SmartHandController
//…

SmartController.h

#pragma once
//#include <Arduino.h>
#include “Pad.h”
#include “u8g2_ext.h”
#include “Telescope.h”
#include “LX200.h”
#include “Globals.h”
//#include “Initialize.h”

class SmartHandController
{
public:
enum OLED { OLED_SH1106, OLED_SSD1306, OLED_SSD1309 };
int telescopeCoordinates=1;
#if DISPLAY_24HR_TIME == ON
boolean hrs24=true;
#else
boolean hrs24=false;
#endif
void update();
void drawIntro();
//…
};

extern SmartHandController HdCrtlr;

and Smartcontroller.cpp

#include “main.h”
#include “SmartController.h”
//…

void SmartHandController::setup(const char version, const int pin[7],const bool active[7], const int SerialBaud, const OLED model)
{
//…
}

//…

Looks like a typo: Sometimes you spell it HdCrtlr and sometimes HdCtrlr.

1 Like

Damn it. This is not really my day, apparently. :thinking: