[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 ... #endif
and my test class header and source files
test.cpp
andtest.h
// test.cpp #include "test.h"
// test.h #ifndef TEST_H #define TEST_H #include "myownconfig.h" #include <MySensors.h> class Test { MyMessage &message; }; #endif
Compiling (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>
-
@user2684 Yes, that is the solution. Thanks a lot!
Suggested Topics
-
Day 1 - Status report
Announcements • 23 Mar 2014, 22:45 • hek 24 Mar 2014, 20:12 -
Compiling Sensor code using BME280 and ESP8266
Troubleshooting • 26 Feb 2025, 00:32 • dpcons 26 Feb 2025, 06:22 -
JSN SR04T - Temperature Influencing Readings
Troubleshooting • 6 Sept 2019, 07:51 • Timbergetter 13 days ago -
Getting system time from the controller
Troubleshooting • 27 Feb 2025, 01:39 • dpcons 3 Mar 2025, 01:00 -
JSN-SR04T-V3.0 Coax cable extended
Troubleshooting • 22 days ago • bocalexandru 20 days ago -
NODs stop responding, but ping works.
Troubleshooting • 8 Mar 2025, 19:47 • Marcin 8 Mar 2025, 19:47