Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Abstract Class Libraries, inheritance and #define problem (Read 2986 times)
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Abstract Class Libraries, inheritance and #define problem
Jul 9th, 2016 at 8:46pm
Print Post  
I am creating a number of class libraries, many of them abstract with multiple alternative concrete classes beneath them. For example, I support at least four different motor types, but any given robot will need only one. If I include all four, I blow the UNO's memory capacity, so I must be able to select only one.

My solution (which doesn't yet work) is to create an "Options.h" file that contains a series of #define statements. E.G.:

#define USE_MotorA  true
#define USE_MotorB  false

Then I want MotorA.h to read the options file and decide whether to include its code:

#include "Options.h"
#if USE_MotorA
... generate the code here
#endif

This approach works fine when all the files are in the same folder as the .ino file, but it breaks down completely when I put MotorA into Libraries/MotorA and Libraries/MotorB, etc.

The problem is that MotorA cannot read the "Options.h" file in the sketch folder. 

So as an alternative, I tried to include MotorA.h and MotorB.h libraries in the .ino definition but this still doesn't make Options.h visible to these files, and I cannot pass the "USE_MotorA" value to MotorA and MotorB.

My research tells me that this is only true with .INO files (not generally true of all C++ environments. 

Can anybody suggest a direction that will work here? My goals are:

1) Each class library is reusable without modification
2) Only the classes required by this INO sketch are included
3) Fits in an UNO.
Lips Sealed
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Abstract Class Libraries, inheritance and #define problem
Reply #1 - Jul 9th, 2016 at 9:17pm
Print Post  
My understanding is that #defines are global

It might be because you have used a folder name called Libraries which will cause the folders to be compiled like Arduino libraries instead of local project code.  The verbose output will show how the code is being compiled.

An alternative is to use the Visual Micro project property called "extra defines".
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: Abstract Class Libraries, inheritance and #define problem
Reply #2 - Jul 9th, 2016 at 11:43pm
Print Post  
I saw several posts that said defines are not global but that sounds like an interesting (and simple) issue to quantify. I will try that out.

The problem I am having now is that the compiler cannot file library files that clearly are there unless I give them a full path name. This only happens with one class. I need more data before I ask your help. So I am pushing forward but it is getting pretty messy as I try to "classify" my code (i.e. turn chunks into library classes. More to follow and thanks for your quick responses.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint