Mutiple definition & first defined here error in own libray

Hello folks,

I rewrite some code mess for a firmware flasher over i2c into a library, but I’m getting multiple definition and first defined here errors. The problem source seems to be the firmware.h.

The idea is this struct:
|–firmware.h ← location with the firmware

Working with in vscode and an esp32-dev-kit.


#ifndef FLASHER_H
#define FLASHER_H

#include <Arduino.h>
#include "firmware.h"

#define SDA_PIN 21
#define SCL_PIN 22

//extern byte CHIP_ADDR;
//extern byte CHIP_DATA[50];

    FLASHER(uint8_t sda = SDA_PIN, uint8_t scl = SCL_PIN);
    void init(byte address = CHIP_ADDR, byte *data = CHIP_DATA);

    /* functions and variable */



#include <Arduino.h>
#include "flasher.h"

FLASHER::FLASHER(uint8_t sda, uint8_t scl)
    : _dataPin(sda), _clockPin(scl)
  /* Code stuff */

void CS43131::init(byte address, byte *data)
  /* Code stuff */


byte CHIP_ADDR = 0x00;

byte CHIP_DATA[50] = 0x00, ... , 0x00;


#include <Arduino.h>
#includer "flasher.h"

#define SDA 21
#define SCL 22


void setup()

void main()

The Error:

.pio\build\esp32dev\liba88\libflasher.a(flasher.cpp.o):(.data.flasher_DATA+0x0): multiple definition of `flasher_DATA'
.pio\build\esp32dev\src\main.cpp.o:(.data.flasher_DATA+0x0): first defined here
.pio\build\esp32dev\liba88\libflasher.a(flasher.cpp.o):(.data.flasher_ADDR+0x0): multiple definition of `flasher_ADDR'
.pio\build\esp32dev\src\main.cpp.o:(.data.flasher_ADDR+0x0): first defined here

It isn’t working with extern declartion too…

I don’t think it will work that way, because it isn’t possible to give over the address and firmware by default? I hope some got a tip for me.


No. Since you have written an array declaration + definition in a header file, and both flasher.cpp and main.cpp include it, both of these .cpp files will want to create a global array called CHIP_DATA and a global variable called CHIP_ADDR, and you thus get the multiple definition error message.

If the variables are just needed in flasher.cpp, move the contents in there.

If the variable is indeed needed, you declare the variables as extern in the header and move the definition of them in the flasher.cpp file.


#ifndef _FIRMWARE_H_
#define _FIRMWARE_H_

#include <Arduino.h> /* byte */
extern byte CHIP_ADDR;
extern byte CHIP_DATA[50];

Thanks! This was it.

So how I understand it, it isn’t possible to define the address and data(firmware) out of the library as separated file. Except, how I was doing it before, include the firmware.h in main.cpp and used the .init(address, data).