Including user libraries in secondary source files

I’m working on a fairly complex project, so my project folder includes a number of .cpp source files beyond the standard .ino file. I’d like to include a couple of libraries (ZigduinoRadio and ADXL345, FWIW) in one of these source files. Here’s the relevant bits of code (much redacted because NDA):

#include <ZigduinoRadio.h>
#include <Adafruit_ADXL345_U.h>
#include "**********.h"

void hardwareInit (void) {
	// start radio

When I try to compile this, I get the following error message:

footStoolHardware.cpp: In function ‘void hardwareInit()’:
footStoolHardware.cpp:44: error: ‘ZigduinoRadio’ was not declared in this scope

I figured this might be a result of the global variable ZigduinoRadio not coming through correctly from the header file, so I tried declaring it extern at the top of the file. It told me the type (cZigduinoRadio, also duly defined in ZigduinoRadio.h). This makes it clear to me that the library is not being included properly.

Any clues for the clueless on how to fix this? I’d like to be able to properly modularize this project, but it’s looking like that might not be possible within the Arduino environment.

I had this problem. I think it has to do with the preprocessor.
So I made a file “include.h” and put my references to global (external) variables and library includes in that file.
But that was not enough, I had to add some includes to the *.ino and *.cpp too.
Include files can be included a number of times, as long as the includes files have something like this:

#ifndef <name>_h
#define <name>_h

Thank you for the pointers. It turns out I need to include them from both the .ino file and the .cpp file but not the .h file. Then, everything works.

I've seen this error when using a newly installed library without restarting the IDE, also check that RADIO_CH is defined in scope.

You can add a simple statement before which should error if RADIO_CH is not defined.


So, it turns out that the redacted stuff includes a lot of defines from the same local header file as RADIO_CH. They all work. As I said above, it turns out the key is to include the libraries from the cpp and ino files, but not the header file.