<Object used elsewhere without problems> was not declared in this scope

Hey everyone,

I’m trying to get the spark up and running with the SparkJson library and UDP. My code was working fine until I added this one function:

int doNothing(JsonObject& randomName) {
    return 0;
}

Regardless of whether I call it or not, if its above the setup function of below the loop function or anywhere in between, I get a whole bunch of errors that I just can’t seem to figure out. Here are some of the errors:

^
simpleudp.cpp:4:15: error: 'JsonObject' was not declared in this scope
int doNothing(JsonObject& randomName);
^
simpleudp.cpp:4:27: error: 'randomName' was not declared in this scope
int doNothing(JsonObject& randomName);
^
In file included from SparkJson/./ArduinoJson.h:7:0,
from SparkJson/SparkJson.h:13,
from simpleudp.cpp:4:
SparkJson/././DynamicJsonBuffer.h: In destructor 'ArduinoJson::DynamicJsonBuffer::~DynamicJsonBuffer()':
SparkJson/././DynamicJsonBuffer.h:20:33: warning: deleting object of polymorphic class type     'ArduinoJson::DynamicJsonBuffer' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
~DynamicJsonBuffer() { delete _next; }
^
simpleudp.cpp: In function 'int doNothing(ArduinoJson::JsonObject&)':
simpleudp.cpp:43:44: error: 'int doNothing(ArduinoJson::JsonObject&)' redeclared as different kind of symbol

^
simpleudp.cpp:4:5: error: previous declaration of 'int doNothing'
int doNothing(JsonObject& randomName);
^
make: *** [simpleudp.o] Error 1

Any ideas?

Thanks a bunch,

Eric

Turns out I had to add ArduinoJson:: to the type?

So this worked:

int doNothing(ArduinoJson::JsonObject& randomName) {
    return 0;
}

No idea why though…I didn’t need to prepend that when using JsonObject in my loop()

1 Like

Hi @eaponce

It could be that the Spark preprocessor, which re-arranges your code so you don’t need function prototypes etc., is hurting you in this case. You can try turning it off with a pragma but you will have to also include application.h since the preprocessor does that too.

#pragma SPARK_NO_PREPROCESSOR
#include "application.h"
1 Like