a class doesn't see global.h file unless it's included in the file of the class,

I’ve been struggling to understand why this happens and how to fix it. I will provide all the code, but I want to describe the problem. I have a variable in a file called CGlobals. I have a class called Presenter in another file. When I try to reference a variable from CGlobals, it says xxx has not been declared. If I #include CGlobals.h, it doesn’t compile because it complains of duplicate definition, even though I have the proscribed #ifndef CLOCK_GLOBALS_H stuff at the top of the library. Anyone tell me what’s going on?
I put the whole project in the attached zip file. The three relevant files are CGlobals.h, Presenter1.h, and GUIClock.ino where you can see that CGlobals.h is the first #include file. In the Presenter1.h file you will see an effort to define the WklySched strucutre that I want to import.

This is very frustrating.


David Duehren

GUIclock051120.zip (28.4 KB)

Most people are less than happy about opening an possibly sketchy .zip file. Please attached the individual files of your project.

OK. See attachments. There are many of them, why I used a zip file more than for the compression.

AscClockSpoof.h (13 KB)

CGlobals.h (3.33 KB)

ClockInfo.h (531 Bytes)

config.h (3.5 KB)

Controller.cpp (803 Bytes)

Controller.h (16 KB)

guiclock.h (4.61 KB)

GUIclock.ino (8.12 KB)

GUIclock_GLSC.h (33.2 KB)

PersistentStore.h (1.28 KB)

Presenter1.h (13.9 KB)

RenderingInfo.h (576 Bytes)

StoredInfo.h (473 Bytes)

WifiMgr.h (13.2 KB)

Variables should not be defined in header files like CGlobals.h. They should only be declared (extern) there. Otherwise you will have multiple definitions if the header gets #include(d) into multiple compilation units. See Reply #3 Here.

Also: https://www.cprogramming.com/declare_vs_define.html

Thanks, after putting in externs in .h and moving initialization and definition out, I've was able to compile, etc. But I still find that working with a large number of files to be error prone in unexpected ways. Something that compiled last night is giving me errors this AM. I suspect I don't understand what and when files in large sketches get saved or not that later lead to problems.

  • David