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
Hot Topic (More than 8 Replies) Compilation errors (Read 3155 times)
radders
Junior Member
**
Offline


Posts: 13
Location: Coventry, UK
Joined: May 31st, 2018
Compilation errors
May 31st, 2018 at 11:17am
Print Post  
Hello,
I've got some code which is controlled by
Code (C++)
Select All
#define 

and
Code (C++)
Select All
#if 

directives. If I set the
Code (C++)
Select All
#define KEYPAD 0 

, the compilation fails,
but it compiles ok in the Arduino Studio.

The errors thrown are:
178:18: error: variable or field 'keypadEvent' declared void
Error compiling project sources
Debug build failed for project '<project>'
   * <comment line>
 
<project>.ino: 178:18: error: 'KeypadEvent' was not declared in this scope


What is weird is that line 178 isn't even a code line; it is in the middle of a block of comments...

The code I think it is complaining about begins:
Code (C++)
Select All
#if KEYPAD
void keypadEvent(KeypadEvent key)
{ 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compilation errors
Reply #1 - May 31st, 2018 at 11:20am
Print Post  
You have debug enabled and it's possible you have a breakpoint in an invalid position that references the keypadEvent

Try changing the tool bar from Debug to Release and then build again.
  
Back to top
IP Logged
 
radders
Junior Member
**
Offline


Posts: 13
Location: Coventry, UK
Joined: May 31st, 2018
Re: Compilation errors
Reply #2 - May 31st, 2018 at 11:30am
Print Post  
I tried changing to 'Release' and all it did was to change the line number of the error (it became 177)...

Can't see any breakpoints set.
  
Back to top
 
IP Logged
 
radders
Junior Member
**
Offline


Posts: 13
Location: Coventry, UK
Joined: May 31st, 2018
Re: Compilation errors
Reply #3 - May 31st, 2018 at 11:38am
Print Post  
I found that if I comment out the entire method
Code (C++)
Select All
void keypadEvent(KeypadEvent key)
{...}  


it compiles OK. This is strange, because the
Code (C++)
Select All
#if KEYPAD 


should remove it anyway...
It's as if the
Code (C++)
Select All
#if 

is being ignored.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compilation errors
Reply #4 - May 31st, 2018 at 11:39am
Print Post  
Hi,

Thanks, it's important to use Release mode to remove possibility of confusion

I assume your code is in .ino file not .cpp? If so then add your own prototype for the method for your user type as follows. Notice a prototype is the same signature as the method but with ; on the end.

Code
Select All
void keypadEvent(KeypadEvent key);

void keypadEvent(KeypadEvent key)
{
} 

  
Back to top
IP Logged
 
radders
Junior Member
**
Offline


Posts: 13
Location: Coventry, UK
Joined: May 31st, 2018
Re: Compilation errors
Reply #5 - May 31st, 2018 at 11:53am
Print Post  
Tim,

Why would I need to add a prototype to my .ino file when the code is (or should be) being excluded by the #if ?

I don't have any problems when
Code (C++)
Select All
#define KEYPAD 1 


is in use
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compilation errors
Reply #6 - May 31st, 2018 at 11:57am
Print Post  
Hi,

Maybe you don't need it. If KeypadEvent is not also defined in the .ino then you don't need it. If KeypadEvent is defined in the .ino code then you need to place your own prototype in a valid location.

Let's step back and assume KeypadEvent is a standard teensy type so you do not need a prototype.

What do you see in the arduino ide when you attempt to compile?
  
Back to top
IP Logged
 
radders
Junior Member
**
Offline


Posts: 13
Location: Coventry, UK
Joined: May 31st, 2018
Re: Compilation errors
Reply #7 - May 31st, 2018 at 12:09pm
Print Post  
KeypadEvent is defined in keypad.h:
Code (C++)
Select All
typedef char KeypadEvent; 


, but that isn't pulled in when
Code (C++)
Select All
#define KEYPAD 0 


is used:
Code (C++)
Select All
#if KEYPAD
#include <Keypad.h>
#endif 



Compiling in Arduino Studio yields:
Sketch uses 5436 bytes (2%) of program storage space. Maximum is 253952 bytes.
Global variables use 349 bytes (4%) of dynamic memory, leaving 7843 bytes for local variables. Maximum is 8192 bytes.

which seems to indicate it built ok.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compilation errors
Reply #8 - May 31st, 2018 at 12:14pm
Print Post  
Hi,

Arduino made a new parser but it breaks easily so they are working on a better one for 1.9. We will move to that because the interim isn't a great solution and is slow.

In the meantime, you have defined a user-defined type in your .ino code so add the prototype as suggested

If this code was in .cpp file you would need to add the prototype normally. I agree that the #if condition would negate that  in this case but as a general rule prototypes are good.

Thanks
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint