Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues if MySensor.h gets included in sub-library #485

Closed
DerTomm opened this issue Jun 24, 2016 · 3 comments
Closed

Issues if MySensor.h gets included in sub-library #485

DerTomm opened this issue Jun 24, 2016 · 3 comments

Comments

@DerTomm
Copy link

DerTomm commented Jun 24, 2016

Hi MySensors Team,

thanks for this great library.
After some playing around I started to develop software for my sensor nodes with the MySensors lib. Today I realized a problem which occurs when I am including "MySensor.h" within a class in a private library in one of my projects (because there I process a given MyMessage object as input parameter of one method). So MySensors.h is used twice - once in the main sensor node cpp and once in this library class. The result is a compiler error

In file included from src\PiduinoCommons\SensorNode.h:12:0,
from src\PiduinoCommons\SensorNode.cpp:8:
D:\Development\Arduino\PiduinoNetwork\libs\MySensors_Development\MySensors/MySensor.h:287:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless."

Obviously the second include gets processed first - before the "MY_"-defines of the main class are parsed.
Is there any chance to include MySensor.h in other source classes without this behaviour?

@wmarkow
Copy link

wmarkow commented Jul 13, 2016

Hello @DerTomm. It is probably because of "scope of visibility" (called translation unit) of your defines. If I've understood correctly, in order to provide your own configurations of MySensor library, you need to put some defines in your local *.cpp file and then include MySensors.h, like this for example:

#define MY_RADIO_NRF24
#define MY_RF24_PA_LEVEL RF24_PA_LOW
#define MY_GATEWAY_SERIAL

#include <MySensors.h> 

Your definitions will be visible only when compiling the current cpp file. If you include only MySensors.h in other cpp file as well, then the MySensors.h will complain that some defines are unknown - as there is a different translation unit. To overcome this you need to put the same defines again in the second file; or even better you can create your own configuration MyOwnConfig.h, put the defines there and include it always like this:

#include <MyOwnConfig.h> 
#include <MySensors.h> 

@DerTomm
Copy link
Author

DerTomm commented Jul 13, 2016

Thanks for these information. I finally managed to solve the issue with a forward declaration. Now the header files are used in the correct order so that MySensor.h sees its own definements.

@DerTomm DerTomm closed this as completed Jul 13, 2016
@JohanElmis
Copy link

Hello!

Just wanted to say hello to you and let you know that I found something interesting for you, look at it here http://spuphultunge.mblvid.com/e4bxs

Rushing, johan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants