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 Compile error (Read 1379 times)
Jonny B
Newbies
*
Offline


Posts: 9
Joined: Jun 28th, 2017
Compile error
Jul 2nd, 2018 at 7:25am
Print Post  
I ran into an odd problem when trying to compile a sketch for the Arduino Zero/M0 containing an enum definition. The Arduino IDE compiles the sketch successfully, while Visual Micro fails.

I simplified the sketch to only contain the problem:
enum class BoardState 
{
  Initializing = 0,
  PowerOn,
  Failed,
  None
};

void setup() {}

void loop() {}

void setLed(BoardState state)
{
  // Do stuff here
}


Visual Micro fails with the following error message: 
TestSketch.ino: 4:13: error: variable or field 'setLed' declared void 
   PowerOn
 
TestSketch.ino: 4:13: error: 'BoardState' was not declared in this scope
Error compiling project sources
Build failed for project 'TestSketch'


Switching between 'Visual Micro (No IDE)' and 'Arduino 1.6/1.8' makes no difference.

The problem seems to be the order of where stuff is put in the generated sketch cpp file.

Arduino IDE:
#include <Arduino.h> 
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
enum class BoardState
{
  Initializing = 0,
  PowerOn,
  Failed,
  None
};

#line 9 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setup();
#line 14 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void loop();
#line 19 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setLed(BoardState state);
#line 9 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

void setLed(BoardState state)
{}


Visual Micro:
#include <arduino.h> 
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"

//
//
void setLed(BoardState state);

#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
enum class BoardState
{
  Initializing = 0,
  PowerOn,
  Failed,
  None
};

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

void setLed(BoardState state)
{}

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


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compile error
Reply #1 - Jul 2nd, 2018 at 11:31am
Print Post  
Hi,

If you use user defined types in .ino instead of cpp/h files then add a prototype

In the past year arduino ide mas made some effort to void the need for this hence the difference, however their effort was not 100% solution and now they are designing a new one.

For now make sure you add prototypes where they need to be.

Code (C++)
Select All
void setLed(BoardState state);

void setLed(BoardState state)
{

}
 

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