[ESP32] 'does not name a type' error with custom header file

I'm trying to build a modular code for ESP32 (using the Arduino wrapper) and using the BluetoothSerial library. But getting 'BluetoothSerial' does not name a type error. After googling and trying out a few posted solutions it's not working. But the weird thing is, the same code is working under Linux (same IDE version and ESP32 wrapper, 1.8.19 and 2.0.2 respectively).

My main ino file (test.ino)

#include "spp_serial.h"

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

My header file (spp_serial.h)

#ifndef SPP_SERIAL_H
#define SPP_SERIAL_H
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

#endif

I've tried changing the file name, the include guards (like __SPP_SERIAL_H__). Unfortunately I don't know what is going on or how Linux is able to compile it. What difference does it make in Linux.

Exact error message/log

In file included from C:\Users\gogo\Documents\sketches\test\spp_serial.h:3,
                 from C:\Users\gogo\Documents\sketches\test\test.ino:1:
C:\Users\gogo\Documents\sketches\test\bluetoothserial.h:5:1: error: 'BluetoothSerial' does not name a type
In file included from C:\Users\gogo\Documents\sketches\test\test.ino:1:
spp_serial.h:5:1: error: 'BluetoothSerial' does not name a type
 BluetoothSerial SerialBT;
 ^~~~~~~~~~~~~~~
exit status 1
'BluetoothSerial' does not name a type

Pictures:

On windows:

On Linux:

Only if you activate verbose output and all compiler-warnings
and then post the complete content of the output-window as a code-section
it will be possible to analyse what causes the error.

best regards Stefan

Hello @StefanL38. I was able to fix the issue. Don't know what the issue was but after restarting the IDE the issue is fixed. I suspect the issue was the spp_serial.h file as initially it was bluetoothserial.h and after changing the file name I had not restarted the IDE, so maybe some left over cache was causing the issue. But I still don't know how Linux was able compile it.

Thanks.

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