How can one use MyMessage class in library?



  • 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;


  • Admin

    @matkor like that:

    #define MY_CORE_ONLY
    #include <MySensors.h>
    MyMessage MyVar;
    
    void setup() {}
    void loop() {}
    


  • @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.
    
    


  • 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;
     }
    


  • @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.


Log in to reply
 

Suggested Topics

  • 5
  • 2
  • 2
  • 58
  • 12
  • 13
  • 14
  • 8

219
Online

9.2k
Users

9.9k
Topics

103.2k
Posts