Build Error with ESP32 - undefined reference


I got a problem while compiling my code.


pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x28): undefined reference to `DMX::Initialize(DMXDirection)'
.pio\build\esp32dev\src\main.cpp.o: In function `setup()':
C:\Users\rober\Documents\PlatformIO\Projects\LED-Anzug_Master_32/src/main.cpp:31: undefined reference to `DMX::Initialize(DMXDirection)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1

My Code:

#include <WiFi.h>
#include "esp_now.h"
#include <dmx.h>

uint8_t Slave1_Adress[] = {0x5C, 0xCF, 0x7F, 0xD3, 0xA7, 0x1D};
uint8_t Slave2_Adress[] = {0x80, 0x7D, 0x3A, 0x52, 0x19, 0xA7};

typedef struct Color_data {
  int id;
  int r;
  int g;
  int b;
} Color_data;

Color_data Slave1_head;
Color_data Slave1_body;

Color_data Slave2_head;
Color_data Slave2_body;

esp_now_peer_info_t peerInfo;

void senddata(const uint8_t *mac_addr, esp_now_send_status_t sendStatus) {
  if (sendStatus != 0){
    Serial.println("Send-Status: Fail");

void setup() {



  if (esp_now_init() != 0) {

  esp_now_register_send_cb(senddata); = 0;  
  peerInfo.encrypt = false;
  memcpy(peerInfo.peer_addr, Slave1_Adress, 6);
  if (esp_now_add_peer(&peerInfo) != ESP_OK){
    Serial.println("Failed to add peer 1");
  memcpy(peerInfo.peer_addr, Slave2_Adress, 6);
  if (esp_now_add_peer(&peerInfo) != ESP_OK){
    Serial.println("Failed to add peer 2");

void loop(){ = 0;
  Slave1_head.r = map(analogRead(A0), 0, 1024, 0, 500);
  Slave1_head.g = 100;
  Slave1_head.b = 50;

esp_now_send(Slave1_Adress, (uint8_t *) &Slave1_head, sizeof(Slave1_head));


The dmx.h as well as the dmx.cpp file is located inside the “include” folder

I dont have a fucking clue what the problem is, and what they mean with “undefined reference”, i never got this error before.

Hope you can help me.

.cpp files in include/ are not compiled. It’s for header files only. Move dmx.cpp into src/.

1 Like

thanks for the incredible fast answer.
it works

I didn’t know that they were only compiled in in src/

You can also encapsulate it as a library with the standard folder structure. That is, e.g. create lib/dmx and put dmx.cpp and dmx.h in this folder and recompile.

1 Like

Ok, good to know

Then i have to change the #include to dmx/dmx.h, right?

No, the library dependency finder will add the discovered libraries (dmx) to the include path and you can do #include <dmx.h> without any modifications.

1 Like