Problem with #define in included file



I was updating and adding more funcitionality to my application, so I defined a new state and assigned it a constant that was added to the constant list in some included file “adtional.h”. Surprisingly when compiling this new version the defined constant is not found or recognized and a compiler error is generated. Then if I add the same #define line in the main .ino program, everything works ok. The definitions of the constants for the old states were recongnized previously and so they are still recognized giving no error.

// Estados
 #define NOCON   0
 #define INIT    1
 #define LOOP    2
 #define HWIFI   3

You can see the list of states as they appear in the .h file; the last one, HWIFI is not recognized.

I presume it is a problem due to the way the compiling system transforms the input files.



Hmm… Just tested and it seems ok for me


Yes, and it should work, and it worked for me the first time when I had only 3 constants. But when I edited my project and added the new HWIFI definition, it is not recognized when compiling and an error is given. If I put the same define line in the main .ino program, everything works. So I think it is a problem issued when processing the source files for compilation.



You mentioned an error twice, but never really told us which one - this might help, tho’ :wink:

And for your use, I’d even suggest to declare an enum for all your states, rather than #defineing them. Especially common terms like INIT and LOOP might sooner or later interfere with other definitions.


I know that I did not offer any code, but I think the problem is well described. It is not a programming one, the issue is that the define line is not found by the system when I modified the original .h file, but the same line in the main file is found and used to find the value for the symbol. It is not a programming but an environment issue. May be derived from a misuse of it due to my lack of experience with these tools, I don’t know.

Regards and thank you


I’m not talking about the code, but the error message(s)

And when you mention the environment, it would be good to know which environment you’re using/refering to (OS, Web IDE, Particle Dev, local toolchain, …)


Your comment makes a lot of sense. I am using the Web IDE, and the errors are

agksecond.cpp:56:14: error: 'HWIFI' was not declared in this scope
agksecond.cpp: In function 'void loop()':
agksecond.cpp:96:14: error: 'HWIFI' was not declared in this scope

in spite of the fact that the list of defined constants of my first post is in the file “aditional.h” and the line

 #include "aditional.h"

is the number 11 of agksecond.ino

Regards and thank you.


OK, that’s something to work with :wink:

So some stabs in the dark, since sometimes the Web IDE preprocessor gives me headaches too.

First try to remove the leading blank in your #include line (it shouldn’t make any difference, but who knows ;-))
Do the same with your #define lines.

Try to make some functional changes to the header file (e.g. add an actual variable) and try to refer to this in your code, to see if this is only limited to #define or if something goes wrongwhen saving your project.
Try explicitly saving each individual file, before hitting build.

Are you getting any redefined warnings?
Have you got an aditional.cpp too? (are they spelt the same or is one maybe additional?)


Considering what you are tryiing to do, it seems like you may wish instead to create a new variable type. You can do that with enum.

typedef enum{
} losEstados;

losEstados miEstado = NOCON;

void setup() 
  losEstados nuevoEstado = LOOP;
  if (nuevoEstado == miEstado) 
    Serial.println("son los mismos");
    Serial.println("son diferentes");

void loop() 



Well, I have found a solution, but not the problem. I am going to explain, because the problem is exposing the webIDE to impatient developpers like me :wink:

My project was created copying a first version. When creating and copying files, I do not know exactly how, but two aditional.h files shown as different tabs, but being related to the same file -both where updated at the same time, and deleting one forced the deletion of both.

Now I have copied the contents, deleted both -or one?- files, created a new additional.h -yes, the cpp file was called addtional.cpp, but changing the original aditional.h to additional.h didn’t solve anything- and now it works.

Really I do not feel comfortable with the webIDE, although things are improving with practise. But some strange behaviour as the one I have found is happening “de facto”. Nevertheless I think the effort of the Spark team and the community is getting a good sinergy. I am looking forward to get my Electron to go on developing.

Thank you for your support.


for that reason, I started to work in Particle Dev and have not looked back… everything stored tidily in a single directory is better for my brain!


@BulldogLowell, that was what I suggested already :wink:

And @mermaja, that double file thing is a known bug that will be dealt with (some time in the future :wink: - have a search on the forum), but would have been worth mentioning too. It’s difficult to help on the basis of mostly omitted but crucial information (error msg, dev env, experienced issues, …).


i guess that makes the advice twice as valuable… :wink:


If it only were heeded :wink:
(no offence intended - we do like to wind people up from time to time - at least I :stuck_out_tongue_winking_eye: do in a “nice” way)


Hello again, and thank you for your advises.

I think nevertheless that you are not being totally fair. Before posting my problem, I have searched the forum but I was not aware of the relation with the duplicated file issue.

Furthermore I have posted the problem when my application was running, and at the end, I have created a nice, problemless -does this word exists? :slight_smile: - project in Particle’s cloud. So my aim when posting has been to help the community by stating a problem, not trying to bother anyone with my tribulations.

This statement is just to defend my position :wink: . I really appreciate the activity of the forum and the support of the elites. But please, don’t make me feel guilty for posting :smile: Nevertheless I will go on posting if I feel that my humble contributions may help other people to avoid the same stones on the road.

Thank you very much.


@mermaja, sorry if you took my comments as unfair, I didn’t intend to hurt your feelings and I want to encourage you to keep on posting whatever question you have.
We do like helping and we will.

Just as a rule of thumb: Rather provide more info than too little.

For some other clues have a look at