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 Adding library doesn't work if sketch not an ino (Read 4559 times)
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Adding library doesn't work if sketch not an ino
Jan 21st, 2020 at 6:03am
Print Post  
If the solution uses a .cpp and .h file instead of a .ino file then adding libraries does not work. 

i.e. Project contains:
Sketch1.ino (file with just comments)
Sketch1.cpp (file with main and loop)
Sketch1.h (header files)

Adding a library (either user defined or built in) sets the focus on the .ino file but no headers are added.

When the project is an .ino file everything works correctly.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Adding library doesn't work if sketch not an ino
Reply #1 - Jan 21st, 2020 at 1:21pm
Print Post  
Your report is not clear. The project must have a project_name.ino for Visual micro to work. If you uses a project_name.cpp you still need the .ino even if it is empty. 

When using a cpp adding a library will add to the .ino but the compiler will ignore. The .ino can then be treated simply as an example of what you need to do.

For general .cpp and .h files you need to add the #includes yourself, this operates the same way that the arduino ide operates.



  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Adding library doesn't work if sketch not an ino
Reply #2 - Jan 21st, 2020 at 1:55pm
Print Post  
I'll try to clarify:
The project has 3 files:
project_name.ino
project_name.cpp
project_name.h

project_name.ino is only comments, no code
project_name.cpp contains the functions main() and loop()
project_name.h contains #include "arduino.h"

When I add a library using the vMicro Add Library menu the header is not added to the .ino or the .h. The .ino is opened in a new tab (if it isn't already opened) or focus is changed to the .ino if it is open but nothing is added. I'm sure in previous versions this worked and the library header was added (even if I then had to move it to the .h file).

If I have just project_name.ino then the header is correctly added to the .ino file.
« Last Edit: Jan 21st, 2020 at 1:56pm by Acuario »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Adding library doesn't work if sketch not an ino
Reply #3 - Jan 21st, 2020 at 4:16pm
Print Post  
When you use a .cpp override you have to add #includes yourself because you have elected to have full control. However the compiler should continue to resolve the libraries and build correctly. The serial debugger will also no longer work.

Does this make sense? Is there a reason you have dumped the .ino?
  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Adding library doesn't work if sketch not an ino
Reply #4 - Jan 21st, 2020 at 4:35pm
Print Post  
Ok, yes makes sense. 
My reason for dumping the .ino is that it's a big project and for maintainability it is easier. I suppose I can add the .ino back in and just use it as a stub to call other functions.

The functionality I would have expected when adding a header using vm would have been either add the header file to the .ino or to the .h with the same project name. It was a bit disconcerting for vm to go through all the steps and then for nothing to appear.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Adding library doesn't work if sketch not an ino
Reply #5 - Jan 21st, 2020 at 4:43pm
Print Post  
Understood but that isn't how arduino works. It's also difficult to work out in a .cpp where to add the includes, whereas an .ino has simpler format so the includes just go before the first line of code. All there is to adding a library is the #include which is why visual micro continues to add them to the .ino so that you can see what to copy into your .cpp

As you say most code can go in a .cpp but with different name or your project_name.cpp might be same as .ino in which case keep the .h and the .ino but dump the .cpp
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint