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 Using CPP & Header-files instead of INO (Read 5799 times)
irPaul
Newbies
*
Offline


Posts: 2
Joined: Oct 23rd, 2017
Using CPP & Header-files instead of INO
Oct 23rd, 2017 at 4:33pm
Print Post  
Hi,

I'm testing Visual Micro in Visual Studio 2017 Community for larger projects at the moment, but I'm getting stuck on how to use CPP & Header files with Visual Micro. According to the manual it should be possible, even recommended to do so!
Currently I use Eclipse with the Sloeber plugin, and this allows me to make Arduino projects with .CPP and .H instead of an .INO. If VM works well, I will migrate all projects.

In Atmel Studio 7 with VM I've managed to write a CPP&H version of Blink by creating a new Arduino project, doing "Add>Empty Arduino CPP and Header file" and then deleting the original .ino. That worked, and remained working after restarts. When I try the same in VS however, it works until I restart VS and open the solution again. The project is not recognised as Arduino-project until I create a new INO-file in it.

Since the User Guide recommends switching to CPP and Header files instead of INO's, can you tell me how to do that? That would make me really happy!  Grin

Thanks in advance!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using CPP & Header-files instead of INO
Reply #1 - Oct 23rd, 2017 at 4:55pm
Print Post  
Hi,

First of all the user guide does not recommend switching away from .ino. If you have atmel hardware debug then the atmel page explains how to do it but it is not recommended because it takes away a lot of things that happen automatically. 


An arduino project for visual micro is a c++ project that contains a "project_name.ino" in a folder called "project_name". This is inline with the arduino ide.

An arduino project can also contain unlimited cpp and/or header files.

Visual Studio is the best tool if you do not have atmel hardware debug.

If you want to entirely avoid .ino files you an create a project_name.cpp in your project. Then the .ino files will be ignored. In this mode for visual micro to work you would at least need an empty project_name.ino but as I have stated the code in the .ino will be ignored so it can contain scratch pad or reference code.

If you use a project_name.cpp then you should ensure you add your own prototypes and also add the arduino.h header. When adding Arduino Libraries the #include headers will not be added to the cpp code but will be added to the unused project_name.ino for reference. You need to then add #includes for new libraries manually to any .cpp files you want to use the library from.

Keep in mind that in all situations Arduino Libraries are #included without a path specifier.
  
Back to top
WWW  
IP Logged
 
irPaul
Newbies
*
Offline


Posts: 2
Joined: Oct 23rd, 2017
Re: Using CPP & Header-files instead of INO
Reply #2 - Oct 24th, 2017 at 6:37am
Print Post  
Thanks for the reply, I will try it with the empty INO file.

To quote your own user manual:
Quote:
If you don't want to learn about C++ declarations and header files, stay with .INO files
If you have a more complex sketch with many separate source files that use classes and methods from each other, you will have more control and overview if you use "classic" C++ .CPP and .H files


For me that is a clear recommendation to switch to CPP and Headers for large projects - which is exactly what I have been doing in Eclipse. That is also the main point for most people to move away from the Arduino "IDE", since having all the code in one big INO-file is a big mess.
I am aware that I have to do my own includes and prototypes.

Maybe it's good to add at least this rule of the empty INO in the user manual? I'm sure more people like me are looking for this solution to develop larger projects, outside of the Arduino IDE, with C++ conventions.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using CPP & Header-files instead of INO
Reply #3 - Oct 26th, 2017 at 11:47am
Print Post  
Hi,

Arduino supports multiple .ino files and supports both .ino and .cpp.

Moving to .cpp is not something I want normal less experienced users to do. It negates a lot of the arduino documentation and requires additional support.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint