Multiple definition of `BLE2902::BLE2902()' when used in header

Hi. I finished one of my projects a couple months ago totalling almost 600 lines of code. It's absolutely unbareable to further develop it. I'm expecting thousands more lines of code before I'm done.

What I need is a .h / .c pair, sounds easy right? nope.

My structure is such that
my.ino
-> #include <esp32_ble.h>
-> -> #include <BLE2902.h>

there is only one line which states #include <BLE2902.h> and it is within my esp32_ble.h
the error is get is

libraries\BLE\BLE2902.cpp.o: In function `BLE2902::BLE2902()':
C:\Users\Paris\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\BLE\src/BLE2902.cpp:17: multiple definition of `BLE2902::BLE2902()'
sketch\src\BLE2902.cpp.o:sketch\src/BLE2902.cpp:17: first defined here
libraries\BLE\BLE2902.cpp.o: In function `BLE2902::BLE2902()':
BLE2902.cpp:(.text._ZN7BLE2902C2Ev+0x0): multiple definition of `BLE2902::BLE2902()'
sketch\src\BLE2902.cpp.o:BLE2902.cpp:(.text._ZN7BLE2902C2Ev+0x0): first defined here
libraries\BLE\BLE2902.cpp.o: In function `BLE2902::getNotifications()':
BLE2902.cpp:(.text._ZN7BLE290216getNotificationsEv+0x0): multiple definition of `BLE2902::getNotifications()'
sketch\src\BLE2902.cpp.o:BLE2902.cpp:(.text._ZN7BLE290216getNotificationsEv+0x0): first defined here
libraries\BLE\BLE2902.cpp.o: In function `BLE2902::getIndications()':

i've been battling this issue for about 4 hours and cannot do it anymore. It's beyond my understanding that a include can only work within the main .ino

I cannot have my header file without #include <BLE2902.h> as i make definitions such as extern BLEServer ^pServer; that are reliant on the BLE library.

you should post both files.

the "#include <BLE2902.h> should only have to be in your .h, assuming your .h is included in your .cpp, but there could be other reasons.

looks like both the library and your sketch have a file names BLE2910.cpp.

esp32_ble.cpp

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

void ble_check_connection(){
  // disconnecting
  if (!deviceConnected && oldDeviceConnected) {
      delay(500); // give the bluetooth stack the chance to get things ready
      pServer->startAdvertising(); // restart advertising
      Serial.println("start advertising");
      oldDeviceConnected = deviceConnected;
  }
  // connecting
  if (deviceConnected && !oldDeviceConnected) {
  // do stuff here on connecting
      oldDeviceConnected = deviceConnected;
  }
}

esp32_ble.h

#ifndef ESP32_BLE_H
#define ESP32_BLE_H

#include <Arduino.h>
#include <stdio.h>
#include <string.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include "defines.h"

extern int pumping;

#define SERVICE_UUID           "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID    "beb5483e-36e1-4688-b7f5-ea07361b26a8" // BLE_write TEST

#define UUID_PUMP_SERVICE       "9046e22b-0c87-45df-9844-50f0cfafa708"

extern BLECharacteristic *PUMP_TOGGLE_Characteristic;

extern BLEServer *pServer;
extern bool deviceConnected;
extern bool oldDeviceConnected;
extern uint8_t txValue;

void ble_check_connection();

#endif

my.ino

#include <stdio.h>
#include <string.h>
#include <Ticker.h>
#include <EEPROM.h>
#include <defines.h>
#include <esp32_ble.h>

void setup() {
  Serial.begin(115200);

  Serial.println("Timer Started");
}

void loop { }

Hi, @weedwizard
What model Arduino are you writing the code for?
What is the application?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi Tom. I like where you're going with this. Since all of the errors are related to the ESP32 library the board profile could be wrong.

The board I have selected is the "DOIT ESP32 DEVKIT V1"

Hi,
I'm not familiar with BLE2902..
Is it supposed to run on an ESP32?

Have you written some code that just deals with the BLE2902 library?

Tom.... :smiley: :+1: :coffee: :australia:

When the board "ESP32 WROVER" is selected things seem to work.

:pensive: sucks to have spent so much time scratching my head trying to figure out why things weren't working when the problem was a menu selection. Big cheers to Tom as I would have spent even more time chasing my tail looking / debugging code.

Hi,
No worries mate, I think the difference will be in memory, flash partioning etc.

Good to see you are going forward instead of stalled.

Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.