[SOLVED] Multiple source files & including MySensors.h problem
-
Hi,
I am trying to create a sketch with multiple source files (to keep my own classes definitions out of main sketch file), but I am not able to includeMySensors.h.Lets consider the following GatewayESP8266 example (4 files) for NodeMCU 0.9 board:
I have the main sketch file
GatewayESP8266.ino// GatewayESP8266.ino ... #include "myownconfig.h" #include <MySensors.h> ...MySensor config file
myownconfig.h// myownconfig.h #ifndef MYOWNCONFIG_H #define MYOWNCONFIG_H // Enable debug prints to serial monitor #define MY_DEBUG ... #endifand my test class header and source files
test.cppandtest.h// test.cpp #include "test.h"// test.h #ifndef TEST_H #define TEST_H #include "myownconfig.h" #include <MySensors.h> class Test { MyMessage &message; }; #endifCompiling (board NodeMCU 0.9) gives a bunch of errors:
sketch/test.cpp.o: In function `__gdb_do_break': /Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MyGatewayTransport.cpp:69: multiple definition of `g_cont' sketch/GatewayESP8266.ino.cpp.o:/Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MySensorsCore.h:428: first defined here sketch/test.cpp.o: In function `__gdb_do_break': /Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MyGatewayTransport.cpp:69: multiple definition of `_ethernetServer' sketch/GatewayESP8266.ino.cpp.o:/Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MySensorsCore.h:428: first defined here sketch/test.cpp.o: In function `hwInit()': /Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MyGatewayTransport.cpp:69: multiple definition of `hwInit()' sketch/GatewayESP8266.ino.cpp.o:/Users/hynekbaran/Documents/Arduino-ESP/libraries/MySensors/core/MyHwESP8266.cpp:24: first defined here sketch/test.cpp.o: ... collect2: error: ld returned 1 exit status exit status 1 Error compiling for board NodeMCU 0.9 (ESP-12 Module).
The same problem appears with ArduinoPro DimmableLigth test project.Thanks for help!
-
Hi, I think you have a similar issue to mine at https://forum.mysensors.org/topic/6084/including-mysensors-h-in-multiple-files. You don't want to include MySensors.h in the other header files but individual MySensors headers containing the functions you need e.g.
#include <core/MySensorsCore.h> -
Hi, I think you have a similar issue to mine at https://forum.mysensors.org/topic/6084/including-mysensors-h-in-multiple-files. You don't want to include MySensors.h in the other header files but individual MySensors headers containing the functions you need e.g.
#include <core/MySensorsCore.h>
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login