Arduino.h defined identifiers not working outside of main?

I tried using SPIFFS and Arduino.h (especially Serial for now) in header file - but I see this: asd
.h file is located in /lib/FileOperations/ which was created by PlatformIO.
Also include path have:

"C:/Repos/swarm_firmware/lib/FileOperations/"

How to fix this?

Contents of FileOps.h:

#ifndef SPIFFS_H
#define SPIFFS_H
#include "spiffs.h"
#endif

#ifndef ARDUINO_H
#define ARDUINO_H
#include <Arduino.h>
#endif

bool dir(char cd[]);

bool rm(char cd[], char target[]);

bool mkdir(char cd[], char name[]);

bool cp(char cd[], char target[]);

bool mv(char cd[], char target[], char destination[]);

Contents of FileOps.c:

#include "FileOps.h"

bool dir(char cd[])
{
    File mother_directory = SPIFFS.open(cd);
 
    File file = mother_directory.openNextFile();

    while(file)
    {
        Serial.print(file.name() + "\t");
        file = mother_directory.openNextFile();
    }

    return true;
}

By doing #define ARDUINO_H before #include <Arduino.h> you are preventing Arduino.h to include any function or definition, because ARDUINO_H is its include guard and you’ve already defined it. Just #include <Arduino.h>?

1 Like

Your whole header file looks just really wrong. Simply do

#ifndef FILEOPS_H
#define FILEOPS_H

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

bool dir(char cd[]);

bool rm(char cd[], char target[]);

bool mkdir(char cd[], char name[]);

bool cp(char cd[], char target[]);

bool mv(char cd[], char target[], char destination[]);
#endif /* FILEOPS_H*/

Hey Max… Out of curiosity, do you happen to know why the #ifdef doesn’t pick up that the Arduino.h has already been included. Would have through that if you included Arduino.h in main.ccp, and then included your own h/cpp, that since Arduino.h, the preprocessor definition ARDUINO_H used for the guard would have existed and been detectable with a #ifdef/#ifndef test… but it isn’t, so just wondering what I am missing… is there a gcc setting perhaps that influences this?