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 Header files not added to project when using .cpp for setup and loop (Read 2533 times)
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Header files not added to project when using .cpp for setup and loop
Jan 15th, 2018 at 7:24am
Print Post  
In a simple project with an .ino file adding a library adds the header files to the .ino file (as expected).
If I create a .cpp and .h file for my project and move the setup and loop code to the .cpp file (just leaving the .ino with comments) then when I add a library no header files are added.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Header files not added to project when using .cpp for setup and loop
Reply #1 - Jan 15th, 2018 at 12:32pm
Print Post  
That is correct. When you use cpp you are expected to add your own includes. Arduino and Visual Micro only add library includes automatically to .ino file.

If your .cpp is the same name as the .ino then the .ino is ignored during compliation. In this case you also need to add your own cpp prototypes and the arduino.h include.
  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Header files not added to project when using .cpp for setup and loop
Reply #2 - Jan 15th, 2018 at 12:46pm
Print Post  
Ok, thanks then it is by design. 

For interest how does the build system path get updated in this case? Does it happen with the deep search includes or does it need to be done manually?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Header files not added to project when using .cpp for setup and loop
Reply #3 - Jan 15th, 2018 at 6:56pm
Print Post  
Yes as long as you #include using normal arduino lib syntax (without path) the build system and deep search will find the libraries from the cpp files.

General rule: It's okay to use cpp files but don't have one with the same name as the project and don't move the setup/loop out of the project_name.ino. It becomes more of a .cpp project than an arduino project if you don't follow this rule. The debugger won't work if you are using that.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint