PlatformIO Community

Problems using LCDMenuLib2 in PlatformIO

Hello. I am trying to convert one of my Arduino projects to esp32 in PlatformIO. I am trying to run the SerialMonitor Sketch from LCDMenuLib2.
I already converted all the .ino files to .cpp and created a header file header.h containing most of the essential functions.
My problem at the moment is the positioning of the two functions, which are needed in most of the .cpp files of the library.

LCDMenuLib2_menu LCDML_0 (255, 0, 0, NULL, NULL); 
LCDMenuLib2 LCDML(LCDML_0, _LCDML_DISP_rows-_LCDML_DSIP_use_header, _LCDML_DISP_cols, lcdml_menu_display, lcdml_menu_clear, lcdml_menu_control);

if i put them into my header.h like this

#ifndef HEADER_H
#define HEADER_H
#include <Arduino.h>
#include <stdint.h>
#include <LCDMenuLib2.h>
void lcdml_menu_display();
void lcdml_menu_clear();
void lcdml_menu_control();
extern uint8_t _LCDML_DISP_cols;
extern uint8_t _LCDML_DISP_rows;
extern uint8_t _LCDML_DSIP_use_header;

LCDMenuLib2_menu LCDML_0 (255, 0, 0, NULL, NULL); 
LCDMenuLib2 LCDML(LCDML_0, _LCDML_DISP_rows-_LCDML_DSIP_use_header, _LCDML_DISP_cols, lcdml_menu_display, lcdml_menu_clear, lcdml_menu_control);

void mDyn_para(uint8_t line);
void mFunc_information(uint8_t param);
...
#endif

PlatformIO gives me several errors like:

multiple definition of `LCDML_0’; PlatformIO/Projects/LCDMenuLib2_esp32/lib/LCDML/header.h:18: first defined here

wich makes sense to me, because the functions seem to be already defined and is redefined every-time i #include my header.h in the other .cpp files

On the other hand, if i just leave them in the main.cpp and remove them from the header.h i get errors for every other .cpp file that wants to access LCDML

‘LCDML’ was not declared in this scope

Is there any way i can figure out the declaration of the two functions, so i can add them to my header or is there maybe a way to make my first definition in main.cpp global so the other .cpp files can access them?

No definition of global variables in header files. You Already do the correct thing for

but not the

objects.
You need to put those in the header as

extern LCDMenuLib2_menu LCDML_0;
extern LCDMenuLib2 LCDML;

and put the definition of

LCDMenuLib2_menu LCDML_0 (255, 0, 0, NULL, NULL); 
LCDMenuLib2 LCDML(LCDML_0, _LCDML_DISP_rows-_LCDML_DSIP_use_header, _LCDML_DISP_cols, lcdml_menu_display, lcdml_menu_clear, lcdml_menu_control);

into one .cpp file (e.g. src/main.cpp).

1 Like

Yes, thats exactly was i was looking for, thank you again! This fixed my problem.
I was trying to do the declarations like that myself, but got confused with the parentheses. Is there a reason that

void mFunc_information(uint8_t param);

works only with the variable param but

extern LCDMenuLib2 LCDML;

works without it?

I tried to implement a declaration like this for the header.h but couldn’t do it.

LCDMenuLib2_menu LCDML_0 (uint8_t p_id, uint8_t p_param, uint8_t p_configuration, NULL, NULL);