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 Preprocessor - Suggestions Please (Read 2954 times)
n
Junior Member
**
Offline


Posts: 52
Joined: Mar 29th, 2016
Preprocessor - Suggestions Please
Nov 29th, 2016 at 5:08am
Print Post  
Hi Tim,

My project is a mixture of .ino and .cpp files and at the beginning of the main .ino file I have perhaps a dozen pre-processor defines of the form :

#define FEATURE_MINMAX true
#define FEATURE_ALARM false

which I use subsequently to either include or exclude pieces of code. The IDE handles this nicely and greys out the parts of code which are not to be included. 

Although the everything works as expected in the .ino files, it seems that the compiler does not handle the #defines properly in the .cpp files and always excludes my code - even though it is not greyed out by the IDE.

Perhaps this is expected behaviour - I'm not sure?? I can't see this explicitly stated in the documentation.

I have tried using the DEFINES field of the project properties to solve the problem. If I use   

FEATURE_MINMAX true;FEATURE_ALARM false; 

then the .cpp files appear to compile as expected but the IDE flags the following error on the first line of every file in the project :

command-line error: invalid macro definition: FEATURE_MINMAX true

The project seems to compile OK but I would like to get rid of these errors.

What is the recommended way of handling project wide #defines in these circumstances?? 

I find the DEFINES field of the project properties gets very unwieldly with 12 semicolon separated #defines in one long string. Is there a better way of doing this?

Thanks

n      
« Last Edit: Dec 1st, 2016 at 1:13am by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Preprocessor Problems
Reply #1 - Nov 29th, 2016 at 12:40pm
Print Post  
I think you will find it is:-

FEATURE_MINMAX=true;FEATURE_ALARM=false; 

An alternative might be to redefine the compile pattern in a local board.txt

Switch on the verbose and "show build properties" compile then take a look at the c and cpp patterns
  
Back to top
IP Logged
 
n
Junior Member
**
Offline


Posts: 52
Joined: Mar 29th, 2016
Re: Preprocessor Problems
Reply #2 - Nov 30th, 2016 at 4:36am
Print Post  
Hi,

Indeed the = removed the IDE errors.

I took a look at the compile patterns but I think that area is a bit beyond me for now. 

I have solved my problem by putting all the #defines into a separate file "Defines.h" and have included this where required. This avoids the ugly long DEFINES string in the project properties.

Thanks

n
« Last Edit: Nov 30th, 2016 at 4:37am by n »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Preprocessor Problems
Reply #3 - Nov 30th, 2016 at 1:34pm
Print Post  
I think that's the right way to work because it works in Arduino IDE too.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint