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 was not declared in this scope error (Read 2938 times)
SVB
Newbies
*
Offline


Posts: 2
Joined: Sep 13th, 2018
was not declared in this scope error
Sep 13th, 2018 at 7:08am
Print Post  
I get an error in Atmel Studio while compiling the following code:

#include "Debug_I2c.h"
#include "Arduino.h"

int i = 0;

#include <Wire.h>

void setup()
{
  Wire.begin(2);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event

  pinMode(13, OUTPUT);
  Serial.begin(9600);
  while(!Serial);
  Serial.println("begin");
}

void loop()
{
  delay(100);
  Serial.println("test");
  if(i++ > 5) 
  {
    digitalWrite(13, !digitalRead(13));
    i = 0;
  }
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  Wire.write("hello "); // respond with message of 6 bytes
                       // as expected by master
}


Message in the output:

Debug_I2c.cpp: In function void setup()
Error compiling project sources
 
Build failed for project 'Debug_I2c'
Debug_I2c.cpp: 11:18: error: 'requestEvent' was not declared in this scope
   Wire.onRequest(requestEvent); \\ register event


The code compiles fine in Arduino. Do I have to declare the 'requestEvent' somewhere else as well?

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


Posts: 12136
Location: United Kingdom
Joined: Apr 10th, 2010
Re: was not declared in this scope error
Reply #1 - Sep 13th, 2018 at 10:56am
Print Post  
You might not be using visual micro and arduino. This looks like it might be a native atmel build. you need to post the full build output when posting errors.

Does the same code build in the arduino ide?
  
Back to top
IP Logged
 
SVB
Newbies
*
Offline


Posts: 2
Joined: Sep 13th, 2018
Re: was not declared in this scope error
Reply #2 - Sep 13th, 2018 at 11:15am
Print Post  
Here is the full build output:


Compiling 'Debug_I2c' for 'Adafruit Metro M4 (SAMD51)'
Build Folder: etro_m4/Debug"
Summary: Header=1 Prototypes=1 Imports=0
Additional Defines: 
Architecture Tools: abi-gcc/4.8.3-2014q1/bin/"
Api: 1.1806.1-5
Sketch Book: "file:///C:/Users/user/Documents/Arduino"
 
Using Debug_I2c.cpp as the intial project code

Sketch Include Paths
Core Include Paths
Include Path .2.3/cores/arduino"
Include Path .2.3/variants/metro_m4"
 
Deep search for libraries ...
4.8.3-2014q1\bin\arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC  -g   -DF_CPU=120000000L -DARDUINO=10805 -DARDUINO_METRO_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_METRO_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8020 -DUSBCON -DUSB_MANUFACTURER="\"Adafruit LLC\"" -DUSB_PRODUCT="\"Adafruit Metro M4\"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE S/Include/" 0/CMSIS/Device/ATMEL/" ores\arduino" ariants\metro_m4" "C:\Users\user\Documents\Arduino\Debug_I2c\Debug_I2c.cpp" -o "nul"
4.8.3-2014q1\bin\arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC  -g   -DF_CPU=120000000L -DARDUINO=10805 -DARDUINO_METRO_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_METRO_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8020 -DUSBCON -DUSB_MANUFACTURER="\"Adafruit LLC\"" -DUSB_PRODUCT="\"Adafruit Metro M4\"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE S/Include/" 0/CMSIS/Device/ATMEL/" ores\arduino" ariants\metro_m4" ibraries\Wire" "C:\Users\user\Documents\Arduino\Debug_I2c\Debug_I2c.cpp" -o "nul"
Using previous search results: aries\Wire\Wire.cpp
 
Building variant ...
 
  Using previously compiled variant
 
Building core ...
 
Building libraries ...

Using library Wire version 1.0 in folder .2.3/libraries/Wire"
  Using previously compiled file: ebug\Wire\Wire.cpp.o
 
Building project code ...
4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD  -g -DF_CPU=120000000L -DARDUINO=10805 -DARDUINO_METRO_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_METRO_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8020 -DUSBCON -DUSB_MANUFACTURER="\"Adafruit LLC\"" -DUSB_PRODUCT="\"Adafruit Metro M4\"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE S/Include/" 0/CMSIS/Device/ATMEL/" -I"C:\Users\user\Documents\Arduino\Debug_I2c" ores\arduino" ariants\metro_m4" ibraries\Wire" -I"C:\Program Files (x86)\Arduino\libraries" -I"C:\Users\user\Documents\Arduino\libraries" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\bu5kipiw.4jy\Micro Platforms\default\debuggers" ibraries" "C:\Users\user\Documents\Arduino\Debug_I2c\Debug_I2c.cpp" -o Debug\Debug_I2c.cpp.o"
 
Debug_I2c.cpp: In function void setup()
Error compiling project sources
Build failed for project 'Debug_I2c'
 
Debug_I2c.cpp: 11:18: error: 'requestEvent' was not declared in this scope
   Wire.onRequest(requestEvent); \\ register event
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12136
Location: United Kingdom
Joined: Apr 10th, 2010
Re: was not declared in this scope error
Reply #3 - Sep 13th, 2018 at 11:50am
Print Post  
Thanks,

The problem is that an arduino project is compiled in a temp folder. All the .ino code is merged into temp\Debug_I2c.cpp then built.


Because you have added a file called Debug_I2c.cpp to the real project this is taken as an indicator that you want to override normal arduino .ino code.

Rename the Debug_I2c.cpp to something other than the name of the project and it will be ok
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint