1

I created 4 libraries, each in .h and .cpp files, and tested them individually. I kept the project flexibility by defining 3 flags that allow or disallow the usage of the libraries.

When integrating them into project I received linking errors. During the debugging I reduced it to minimum - a single .ino file that contains the minimal declarations and calls; but the error messages are still fired.

I looked at the shrunk code (only 63 lines!) and saw no issue. I'd appreciate any help in finding the issue. enter image description here

The code:

#define RadioIncluded  
#define IrrigationStation  
#define RTCincluded  

/********************************************/

#ifdef RTCincluded  
  class rtcHighLevel
  {
    public: 
      String rtcInterpreter(String cmd);
  };
  rtcHighLevel rtc;
#endif

#ifdef IrrigationStation
class measureEC
{
  public:
  void   initMeasurementStation ();
    String SD12_Parser (String commandLine);
};
  measureEC soilParams;

class valveControl
{
  public:
    void   valveInit();
};
  valveControl valve;
#endif

#ifdef RadioIncluded  
  class LoRaAddClass
  {
    public:
      void   LoRaBegin(long BAND);
  };
  LoRaAddClass LoRaAdd;
#endif

/*********************************************************/
void setup() {
  Serial.begin(9600);
  while (!Serial) {};

#ifdef RadioIncluded  
  LoRaAdd.LoRaBegin(915000000);
#endif

#ifdef IrrigationStation  
  valve.valveInit();
  soilParams.initMeasurementStation();
#endif

#ifdef RTCincluded  
  String s = rtc.rtcInterpreter("A");
#endif
}
/*********************************************************/
void loop() {}
7
  • 2
    I see no code there for the functions, so of course it's not going to compile, and complain about there being no code for those functions.
    – Majenko
    Oct 28 '21 at 17:22
  • If you had problems with the conditional code surrounding your declarations and class definitions in your header, you would receive an error from the compiler proper. That is, you'd get an error about something undeclared or undefined before linking rather than an unresolved symbol at linking. You're going to have to show more of the build output, ideally not as an image, and perhaps the .cpp file content as well.
    – timemage
    Oct 28 '21 at 17:34
  • I second Majenkos comment: You have the declaration of member functions in the declarations of your classes, but you never actually provide an implementation of those functions. You need to provide at least an empty implementation.
    – chrisl
    Oct 29 '21 at 7:46
  • Linking to a library is another beast than separating your sketch into multiple source files. Please make clear what you want to do, and you might want to read relevant chapters about this in the documentation and/or Arduino forum. -- Commonly it is a sign of misunderstanding how libraries work, if you have preprocessor instructions like these conditionals. You might want to learn about the real concept before you try to go on. But as a primitive solution for a simple sItuation it might be OK, however, learn the Right Way as soon as possible. ;-) Oct 29 '21 at 8:10
  • Thank you very much for your constructive comments. Although I built some Arduino small sketches I never wrote such a project. First - the correct terminology I should have used is classes rather than libraries. Secondly, according to Majenko and chrisl, I added some lines of codes to every class declaration, and the errors disappeared. So I proceeded to adding the classes by including them. Oct 29 '21 at 18:51
1

Solved: while initially I devoted sub-directory for every class, no issues when all the classes were brought to the same folder with the INO file all the issues disappeared. Is this a known issue?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.