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. Development
  3. How can one use MyMessage class in library?

How can one use MyMessage class in library?

Scheduled Pinned Locked Moved Development
5 Posts 2 Posters 86 Views 1 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.
  • M Offline
    M Offline
    matkor
    wrote on last edited by
    #1

    How can one use MyMessage class in library?

    When I try to

    #include <MySensors.h>
    

    in my library code I get:
    Arduino/libraries/MySensors/MySensors.h:426:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.

    without include I of course get:

    Button.h:13:5: error: 'MyMessage' does not name a type
    MyMessage msg;

    tekkaT 1 Reply Last reply
    0
    • M matkor

      How can one use MyMessage class in library?

      When I try to

      #include <MySensors.h>
      

      in my library code I get:
      Arduino/libraries/MySensors/MySensors.h:426:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.

      without include I of course get:

      Button.h:13:5: error: 'MyMessage' does not name a type
      MyMessage msg;

      tekkaT Offline
      tekkaT Offline
      tekka
      Admin
      wrote on last edited by
      #2

      @matkor like that:

      #define MY_CORE_ONLY
      #include <MySensors.h>
      MyMessage MyVar;
      
      void setup() {}
      void loop() {}
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        matkor
        wrote on last edited by
        #3

        @tekka said in How can one use MyMessage class in library?:

        #define MY_CORE_ONLY

        It solved compiiation errors, but now I have link errors(I have many .cpp/.h files in my lib):

        /tmp/arduino_build_899057/libraries/MyLib/Foo.cpp.o (symbol from plugin): In function `wakeUp1()':(.text+0x0): multiple definition of `wakeUp1()'
        

        Seems same as https://forum.mysensors.org/topic/6084/including-mysensors-h-in-multiple-files .
        I tried:

        #include <core/MySensorsCore.h>
        

        but it fails:

        Alternatives for core/MyMessage.h: []In file included from mytest.ino:13:0:
        ResolveLibrary(core/MyMessage.h)
          -> candidates: []
        
        MyLib/MyLib.h:10:10: fatal error: core/MyMessage.h: No such file or directory
         #include <core/MyMessage.h>
                  ^~~~~~~~~~~~~~~~~~
        compilation terminated.
        
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          matkor
          wrote on last edited by
          #4

          Switching both clashing functions ( wakeUp1(), wakeUp2() ) to static functions seems to fix linking for me.

          diff --git a/hal/architecture/AVR/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp
          index 5a17b063..a018ab35 100644
          --- a/hal/architecture/AVR/MyHwAVR.cpp
          +++ b/hal/architecture/AVR/MyHwAVR.cpp
          @@ -41,7 +41,7 @@ volatile uint8_t _wakeUp2Interrupt  =
           
           static uint32_t sleepRemainingMs = 0ul;
           
          -void wakeUp1(void)
          +void static wakeUp1(void)
           {
                  // Disable sleep. When an interrupt occurs after attachInterrupt,
                  // but before sleeping the CPU would not wake up.
          @@ -53,7 +53,7 @@ void wakeUp1(void)
                          _wokeUpByInterrupt = _wakeUp1Interrupt;
                  }
           }
          -void wakeUp2(void)
          +void static wakeUp2(void)
           {
                  sleep_disable();
                  detachInterrupt(_wakeUp2Interrupt);
          diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp
          index d91a0438..f083a17c 100644
          --- a/hal/architecture/NRF5/MyHwNRF5.cpp
          +++ b/hal/architecture/NRF5/MyHwNRF5.cpp
          @@ -28,11 +28,11 @@ volatile uint8_t _wakeUp1Interrupt =
           volatile uint8_t _wakeUp2Interrupt =
               INVALID_INTERRUPT_NUM; // Interrupt number for wakeUp2-callback.
           
          -void wakeUp1(void) // place to send the interrupts
          +void static wakeUp1(void) // place to send the interrupts
           {
                  _wokeUpByInterrupt = _wakeUp1Interrupt;
           }
          -void wakeUp2(void) // place to send the second interrupts
          +void static wakeUp2(void) // place to send the second interrupts
           {
                  _wokeUpByInterrupt = _wakeUp2Interrupt;
           }
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            matkor
            wrote on last edited by
            #5

            @matkor said in How can one use MyMessage class in library?:

            Switching both clashing functions ( wakeUp1(), wakeUp2() ) to static functions seems to fix linking for me.

            This sees to be deadend as there come more function name clashes, and i suspect linking problems come from magic done by arduino IDE.

            Current hack for me is include in arduino sketch my lib headers after including MySensors:

            #include <MySensors.h>
            #include <MyLib.h>
            

            and than inside library use only:

            #include <core/MySensorsCore.h>
            

            not sure if its right solution, if one has any better please share.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            18

            Online

            11.7k

            Users

            11.2k

            Topics

            113.0k

            Posts


            Copyright 2019 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