Linker error with new class for gateway



  • Hi,

    I try to extend the gateway with some functionallity. For that I have written some c++ classes that are tested and working and put them in the /core folder.
    But when I compile them in the context of MySensors project I get an linker error:

    ./core/MyGatewayTransportMQTTClient.cpp:136: undefined reference to `SmartSleep::init(std::string)'
    

    Is there anything I have to consider when I introduce new classes that consist of a SmartSleep.h and SmartSleep.cpp file?

    I extend the Class MyGatewayTransportMQTTClient the following way:

    #include "SmartSleep.h"
    ...
    static SmartSleep ss;
    ...
    bool gatewayTransportInit(void)
    {
    ss.init("nodes_smartsleep.cfg");
    

    The classes look like:

    SmartSleep.h
    class SmartSleep {
    	public:
    void init(string);
    
    SmartSleep.cpp
    void SmartSleep::init(string filename) {
       ...
    }
    


  • Problem solved with a not so nice hack 😉

    I moved my additional .h and .cpp files into one of the library folders MySensors\drivers\BCM\ and now the .o file gets compiled and the linker can find the method implementation.

    But why does it not work in the /core folder?



  • Ok now I have found the proper place to include the missing .cpp files to generate the .o files.

    In the MySensor.h are all necessary .cpp files from the /core folder

    #if defined(MY_GATEWAY_LINUX)
    #include "drivers/Linux/EthernetClient.h"
    #include "drivers/Linux/EthernetServer.h"
    #include "drivers/Linux/IPAddress.h"
    #endif
    #include "drivers/PubSubClient/PubSubClient.cpp"
    #include "core/MyGatewayTransportMQTTClient.cpp"
    #include "core/MySmartSleep.cpp"
    #include "core/MySleepNode.cpp
    

Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 2
  • 1
  • 1
  • 6

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts