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) xxxx was not declared in this scope (Read 7856 times)
Max Power
Newbies
*
Offline


Posts: 3
Joined: Feb 25th, 2017
xxxx was not declared in this scope
Feb 25th, 2017 at 12:04pm
Print Post  
I've just encountered an 'xxxx' was not declared in this scope' error after splitting up my ino into multiple ino's. The documentation on this page http://www.visualmicro.com/page/User-Guide.aspx?doc=Frequently-Asked-Questions.h... suggests some reasons for the error but none of them were the cause of my problem. One of my functions had a default parameter which the IDE doesn't seem to like if that function is called from another file. Removing the default fixed the issue.

I just wanted to let people know just in case anyone encounters this problem. And if any Admins are reading, maybe an update to the FAQ page would help? Smiley

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #1 - Feb 25th, 2017 at 12:58pm
Print Post  
Let me know if the following help.

When splitting code into multiple .ino files the order they are joined into a .cpp during compile should be considered 

The [project_name.ino] is appended first so make all declarations/types in that .ino

The uppercase file names are then joined in alphabetical order

The lower case file names are then joined in alphabetical order

Don't shout at me about that I didn't design it.

Another consideration

If your methods accept user defined types that are define in .ino files you need to create a prototype for the method in the correct location. For example

Code
Select All
// creation of a struct
  myStruct{
    int foo;
 }

// prototype of method that uses the struct
  myMethod(myStruct stuc);


// method that uses the struct
 myMethod(myStruct stuc)
 {
 } 



If you switch on "vMicro>Compiler>Show build folder" you will see a link in the build output to the build folder. There you can inspect the project_name.cpp which will be a concatenation of your .ino files used for build.

The arduino ide differs slightly with where is places the prototypes. They use a newer system to insert them automatically which works better but complicates debug. Adding prototypes with user defined types manually is easy (as shown above) and resolves the problem.
« Last Edit: Dec 4th, 2019 at 5:31pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Max Power
Newbies
*
Offline


Posts: 3
Joined: Feb 25th, 2017
Re: xxxx was not declared in this scope
Reply #2 - Feb 25th, 2017 at 1:04pm
Print Post  
I took all of that into consideration. I had two files WebServer.ino and Web.ino in a project called WebServer

Web.ino had a function void Send(String& filename, uint16_t refresh = 0)

WebServer.ino had a call Send(filename);

the error was Send() not declared in this scope

Changing the function to void Send(String& filename, uint16_t refresh) and the call to Send(filename, 0) fixed the issue.

I can see that the Send function could be included after the call, but removing the default parameter fixed it.

Max
« Last Edit: Feb 25th, 2017 at 1:05pm by Max Power »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #3 - Feb 25th, 2017 at 1:10pm
Print Post  
I see thanks v much. 

I need to do some testing with a default param. This might be another benefit of moving to ctags like the arduino ide. 

Did it work in arduino?

I think the issue will be that visual micro still attempted to add the prototype because your prototype would have had a different signature without the default value.
  
Back to top
WWW  
IP Logged
 
Max Power
Newbies
*
Offline


Posts: 3
Joined: Feb 25th, 2017
Re: xxxx was not declared in this scope
Reply #4 - Feb 25th, 2017 at 1:58pm
Print Post  
I've just tried it in the Arduino IDE and it fails with the same error. Removing the default fixes it.

Max
« Last Edit: Feb 25th, 2017 at 1:59pm by Max Power »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #5 - Feb 25th, 2017 at 2:07pm
Print Post  
Ok thanks very much for the effort. Will add to FAQ as you suggest and not attempt to find a solution.
  
Back to top
WWW  
IP Logged
 
PeteB
Newbies
*
Offline


Posts: 2
Joined: Aug 13th, 2017
Re: xxxx was not declared in this scope
Reply #6 - Aug 13th, 2017 at 10:34pm
Print Post  
Hey there, a related follow-up...

I'm facing the same problem with the auto-gen prototypes being declared before the required typedefs are available. Unfortunately, the project isn't mine and the owner isn't really up for the .cpp/manual prototype approach.

I have seen mention an intent to move to the Arduino ctags method but curious what the timetable is on that ?

I also read that the complication is related to debugging, I must admit that I would be happy to wait for debugging if there was a "here-and-now" option for compiling available!

Trying to avoid a return to the Arduino IDE ...
« Last Edit: Aug 14th, 2017 at 12:02am by PeteB »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #7 - Aug 15th, 2017 at 12:36pm
Print Post  
Hi Pete,

You can add them yourself manually with exact same signature is the method. It's easy to do. 

This is why it isn't a priority  Smiley
  
Back to top
WWW  
IP Logged
 
PeteB
Newbies
*
Offline


Posts: 2
Joined: Aug 13th, 2017
Re: xxxx was not declared in this scope
Reply #8 - Aug 15th, 2017 at 3:28pm
Print Post  
Unfortunately, the project owner wont take changes into his repo so I'm stuck with either: 1) making the alterations each time the project is updated (very frequently) or, 2) bypass the visual micro build process.

I have gone for option 2 and added a button onto the Visual Micro Toolbar that calls a powershell script to run arduino-builder.exe with Arduino IDE compatible parameters. The script also parses the build output into VS compatible error/warning message format.

Thanks for the response and totally get priorities!
  
Back to top
 
IP Logged
 
GoofBall
Newbies
*
Offline


Posts: 9
Joined: Jun 22nd, 2018
Re: xxxx was not declared in this scope
Reply #9 - Dec 4th, 2019 at 4:43pm
Print Post  
Tim@Visual Micro wrote on Feb 25th, 2017 at 12:58pm:
Let me know if the following help.

When splitting code into multiple .ino files the order they are joined into a .cpp during compile should be considered 

The [project_name.ino] is appended first so make all declarations/types in that .ino

The lower case file names are then joined in alphabetical order

Lastly the uppercase file names are then joined in alphabetical order

Don't shout at me about that I didn't design it.



Nooo... upper&lowercase are the other way:   the order when assembling the giant .cpp out of all the .ino:

1. function prototypes
2. <projectname>.ino
3. Alphabetical.ino  (uppercase filenames)
4. alphabetical.ino  (lowercase filenames)

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #10 - Dec 4th, 2019 at 4:46pm
Print Post  
Ah. Thanks for the post. Are you saying that I made a mistake in my instructions or that Visual Micro gives different result to the Arduino IDE?
  
Back to top
WWW  
IP Logged
 
GoofBall
Newbies
*
Offline


Posts: 9
Joined: Jun 22nd, 2018
Re: xxxx was not declared in this scope
Reply #11 - Dec 4th, 2019 at 4:57pm
Print Post  
Tim@Visual Micro wrote on Dec 4th, 2019 at 4:46pm:
Are you saying that I made a mistake in my instructions or that Visual Micro gives different result to the Arduino IDE?


No, you just mis-typed in this post.  In the User Guide https://www.visualmicro.com/page/User-Guide.aspx?doc=INOs-and-CPPs.html  you have it correct.

Unfortunately,  I encountered this post first.  Two hours ago Sad


I don't know what arduino IDE does wrt giant.cpp ordering...
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: xxxx was not declared in this scope
Reply #12 - Dec 4th, 2019 at 5:32pm
Print Post  
Sorry about that. Yes docs are correct. I have changed the post.

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