Compiler doesn't find String class in included files

When I describe a function in header file, compiler can’t find String class, even thought I’ve included Arduino.h.

platform = espressif32
board = esp32dev
framework = arduino


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


#ifndef TIME_H
#define TIME_H

#include <Arduino.h>
#include <string.h>

String renderTime(long t);



#include "time.h"
String renderTime(long t) {
  return "test";

On build I get an error from compiler: src/time.h:7:1: error: 'String' does not name a type.

What am I doing wrong?

By naming the file time.h, you have created a duplicate file name (another file of the same name is part of the standard C library). This is causing problems…

Rename the files and stay away from the name time.

Furthermore, there is no need to include string.h. This is a header file from the standard C library. But you are looking for a C++ string class.

When using the Arduino framework, the string class is part of the Arduino framework, so #include <Arduino.h> is sufficient.

1 Like

Ohh… so simple solution! Thank You a lot! :slight_smile: After renaming files everything works as it should!

1 Like