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] 2  Send TopicPrint
Hot Topic (More than 8 Replies) function not declared in this scope (Read 10418 times)
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
function not declared in this scope
Apr 27th, 2018 at 2:26pm
Print Post  
I am using Atmel Studio with the Pro version of VM.  I have written a lot of code with Atmel Studio but this is the first time I have attempted anything Arduino.  At the top of my .ino file I have added a standard header which contains a declaration of a function I wish to use.  In setup() I attempt to call this function, but get the above error.  Any suggestions gratefully received!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #1 - Apr 27th, 2018 at 2:28pm
Print Post  
Post .ino code.

Post error you see.

Thanks
« Last Edit: Apr 27th, 2018 at 2:29pm by Tim@Visual Micro »  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #2 - Apr 27th, 2018 at 3:09pm
Print Post  
/*
* PWMLampController.ino
*
* Created: 4/20/2018 12:52:21 PM
* Author: Marc
*/ 


     #include "HWinit.h"
     



void setup()
{
       /* add setup code here, setup code runs once when the processor starts */
       HWinit(eHWinitStartup);

}

void loop()
{

       /* add main program code here, this code starts again each time it ends */

}

Error...
Warning            HWinit(eHWinitStartup)                  
Warning            In function void setup()            
Error            17:22: error: 'HWinit' was not declared in this scope      
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #3 - Apr 27th, 2018 at 3:10pm
Print Post  
Thanks what is in HWinit.h

Please confirm the error shows when you try to build? Not just intellisense error before first build?
« Last Edit: Apr 27th, 2018 at 3:11pm by Tim@Visual Micro »  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #4 - Apr 27th, 2018 at 4:07pm
Print Post  
Just did a "Rebuild Solution" and the error pops up.  HWinit.h contains all the register settings that I require and a declaration of HWinit():
void hwINIT(hwinit_t initType);

This code is more or less duplicated from a previous project

Arduino board is an Atmega2560
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #5 - Apr 27th, 2018 at 4:24pm
Print Post  
Please zip your project and attach here to save us going around in circles thanks





  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #6 - Apr 27th, 2018 at 4:53pm
Print Post  
Sorry, can't seem to see how to attach a file
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #7 - Apr 27th, 2018 at 5:32pm
Print Post  
when you click reply there is a "chose file" below the message text area but you can email to info[at]visualmicro.com with link this post if easier
  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #8 - Apr 28th, 2018 at 8:43am
Print Post  
Can't imagine how I did not see this before, sorry
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #9 - Apr 28th, 2018 at 12:40pm
Print Post  
I can't open the rar. How about a zip?
  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #10 - Apr 28th, 2018 at 12:56pm
Print Post  
7zip opens Rar files, but here is a zip
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #11 - Apr 28th, 2018 at 1:13pm
Print Post  
Yes I use 7zip but it does not open that .rar

I see your code now in the zip.

You have defined your prototype incorrectly in your hwinit.h


I recommend VS2017 for some people because the intellisense is more helpful in this instance.  Sometimes Atmel intellisense is better for advanced gcc and hardware programmers

Code
Select All
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Declarations

void hwINIT(hwinit_t initType); - WRONG

void HWinit(hwinit_t initType);  - CORRECT
 

« Last Edit: Apr 28th, 2018 at 1:16pm by Tim@Visual Micro »  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #12 - Apr 28th, 2018 at 2:39pm
Print Post  
Oh yes, silly me.  My default coding style is to start with caps but apparently Arduino is the other way around.  I still get an error, but subtley different:

Compiling debug version of 'PWMLampController' for 'Arduino/Genuino Mega w/ ATmega2560 (Mega 2560)'

Error linking for board Arduino/Genuino Mega w/ ATmega2560 (Mega 2560)
 
ccpCmymh.ltrans0.ltrans.o*: In function main
ccpCmymh.ltrans0.o*: (.text.startup+0x232): undefined reference to HWinit(hwinit_t)
Debug build failed for project 'PWMLampController'
 
collect2.exe*: error: ld returned 1 exit status

I might try VS2017 when I am less busy
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #13 - Apr 28th, 2018 at 3:01pm
Print Post  
Try clicking "build>clean solution". Maybe there is a file in the temp build folder that you have since deleted (or renamed) from the project
  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #14 - Apr 28th, 2018 at 3:24pm
Print Post  
Just for a change I included a different header and called a function from it in setup() - same result.  I also tried calling HWinit() in loop() - again an error.  If I comment out the #include for HWinit.h then it correctly complains that it can't see eHWinitStartup - so it must be reading the file. I am at a loss!
  
Back to top
 
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #15 - May 1st, 2018 at 5:23pm
Print Post  
Did you manage to get anywhere with this problem?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #16 - May 4th, 2018 at 8:45pm
Print Post  
Sorry for the delay. You previous attached project builds okay for me so maybe some previous renaming of code files has left the temp build folder in a bad state. Click "Build>Clean Solution" to ensure a clean build.

tip

Keep in mind that removing code from the solution but leaving the files in the project folder will not remove them from builds. The arduino ide would also still attempt to compile these files so visual micro honors this rule (for any code in the project folder.) Un-expected duplicate code can cause the issue you have posted.


  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #17 - May 5th, 2018 at 4:56pm
Print Post  
The problem appears to be that the files have a ".c" extension and the compiler is looking for ".cpp".  Once that is fixed it compiles OK.  However I have been more than a little disappointed with compilation speed and debugging facilities in the Arduino world, so I have erased the boot loader and am now debugging with the JTAG interface.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: function not declared in this scope
Reply #18 - May 5th, 2018 at 5:06pm
Print Post  
Thanks for the update. .c files should be okay as long as they are included and written with c constraints in mind.

Compilation speed is improved if you check "vmicro>compiler>high speed build" because threads are used.

USB upload can be slower than programmer such as JTAG and if you have hardware debug facility then gdb is the way to do.

The different arduino tool chain versions can differ in speed quite a lot.

The serial debug is designed for boards that do not support gdb or that need to be debugged over bluetooth or rf  etc.
« Last Edit: May 5th, 2018 at 5:07pm by Tim@Visual Micro »  
Back to top
IP Logged
 
BlueCat
Junior Member
**
Offline


Posts: 14
Joined: Apr 27th, 2018
Re: function not declared in this scope
Reply #19 - May 5th, 2018 at 5:48pm
Print Post  
Odd that, the project compiles fine as C in Atmel Studio.  I think I had checked the fast build, I am using the latest Arduino tool chain.

Anyway - onwards and upwards.   

Regards,
Marc
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint