PlatformIO Community

Can't use macros outside library header file

Hi! This is my first post so if there’s something that doesn’t go according to the rules please let me know!

Now, to the topic, I’m making an app to control the curtains of my house. I’m using an ESP8266, a stepper motor and Blynk. As it got slightly bigger than what I planned, I’m refactoring the whole projects and splitting it into libraries. One to control the stepper, one for debugging, and so on.

The problem I’m having right now is with the debugging library. For obvious reasons is the first one I started working on. It’s literally just a couple macros for Serial.print(), that will turn to blank if I don’t define DEBUG_ENABLED. I’ve been using that method before (I switched from the Arduino environment to Deviot not long ago), if I define all the macros within the main .ino file, it works okay, but when I move it outside it, to a header file, the .ino file can’t see those functions.
I’ve been googling for the past hour and I can’t really find any clues, so I would appreciate any help :slight_smile:

The code:


#include "SimpleDebug.h"

void setup()

void loop()
    DEBUG_PRINTLN("It works! I guess so...?");



        #define DEBUG_SERIAL_SPEED    115200

    #ifdef DEBUG_ENABLED
        #define DEBUG_INIT          (Serial.begin(DEBUG_SERIAL_SPEED))
        #define DEBUG(code)         (code)
        #define DEBUG_PRINT(text)   (Serial.print(text))
        #define DEBUG_PRINTLN(line) (Serial.println(line))
        #define DEBUT_INIT
        #define DEBUG(code)
        #define DEBUG_PRINT(line)
        #define DEBUG_PRINTLN(line)

The error itself:

In function 'void setup()':
    error: 'DEBUG_INIT' was not declared in this scope

Thank you!

Hello @ferminolaiz


This is why your main can’t find DEBUG_INIT :wink: the rest should work

Thank you! That was a pretty obious one but I clearly didn’t see it hahaha
Have an awesome day!