PlatformIO Community

Undefined reference to problem in lib add two folder

I added two folders under the lib folder, one is guiinc, the other is guisrc, which put header files and source files respectively, and then I call the function in the src/main.cpp file, and it prompts an undefined reference to error, How should I set?

├─include
├─lib
│  ├─guiinc
│  └─guisrc
├─src

main.cpp

#include "gui_guider.h"
#include "events_init.h"
#include "custom.h"
void setup()
{
    setup_ui(&guider_ui);
    events_init(&guider_ui);
    custom_init(&guider_ui);
}

error

Compiling .pio\build\esp32dev\FrameworkArduino\stdlib_noniso.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\esp32dev\libFrameworkArduino.a
Indexing .pio\build\esp32dev\libFrameworkArduino.a
Linking .pio\build\esp32dev\firmware.elf
.pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x0): undefined reference to `guider_ui'
.pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x4): undefined reference to `setup_ui'
.pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x8): undefined reference to `events_init(lv_ui*)'
.pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0xc): undefined reference to `custom_init(lv_ui*)'
.pio\build\esp32dev\src\main.cpp.o: In function `setup()':
C:\Devproject\platformIO\megaesp32/src/main.cpp:73: undefined reference to `setup_ui'
C:\Devproject\platformIO\megaesp32/src/main.cpp:73: undefined reference to `events_init(lv_ui*)'
C:\Devproject\platformIO\megaesp32/src/main.cpp:74: undefined reference to `custom_init(lv_ui*)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1
================================================================================================= [FAILED] Took 25.20 seconds ===========================================================================================

Normally, if you have a library named, for example, “gui”, then you would create lib/gui and put your headers and source files together in the one location.

Cheers,
Norm.

1 Like