Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. [SOLVED] Multiple source files & including MySensors.h problem

[SOLVED] Multiple source files & including MySensors.h problem

Scheduled Pinned Locked Moved Troubleshooting
include mysensors.h
3 Posts 2 Posters 2.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tlustoch
    wrote on last edited by Yveaux
    #1

    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 include MySensors.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 and test.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!

    1 Reply Last reply
    0
    • U Offline
      U Offline
      user2684
      Contest Winner
      wrote on last edited by
      #2

      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>
      
      T 1 Reply Last reply
      2
      • U user2684

        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>
        
        T Offline
        T Offline
        tlustoch
        wrote on last edited by
        #3

        @user2684 Yes, that is the solution. Thanks a lot!

        1 Reply Last reply
        1

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        19

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular