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:
|–main.cpp
|–flasher.h
|–flasher.cpp
|–firmware.h ← location with the firmware
Working with Platiform.io in vscode and an esp32-dev-kit.
flasher.h:
#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];
class FLASHER
{
public:
FLASHER(uint8_t sda = SDA_PIN, uint8_t scl = SCL_PIN);
void init(byte address = CHIP_ADDR, byte *data = CHIP_DATA);
private:
/* functions and variable */
};
#endif
flasher.cpp:
#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 */
}
firmware.h:
byte CHIP_ADDR = 0x00;
byte CHIP_DATA[50] = 0x00, ... , 0x00;
main.cpp:
#include <Arduino.h>
#includer "flasher.h"
#define SDA 21
#define SCL 22
FLASHER flash(SDA, SCL);
void setup()
{
flash.init();
}
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.
Thanks!
fmvoxa