I am using the visual micro extension for Visual Studio 2015. I would like to not use any .ino files since I'm trying to setup cppcheck which doesn't recogonize .cpp files, and its just what I'm used to. However when I change my project.ino file to project.cpp the compile option is no longer available (I assume its looking for a .ino file). Is there a project setting I can change to fix this?
2 Answers
Make a new tab in the IDE (top RH corner) with a xxx.cpp file name. Put your code in that. Leave the .ino file blank. Then it will compile. You need to add:
#include <Arduino.h>
... to the start of the .cpp file.
More information: How to avoid the quirks of the IDE sketch file pre-preprocessing
To clarify the question about libraries ...
You do need to put into the .ino file an include for any libraries used in the project. For example:
#include <Wire.h>
#include <SPI.h>
#include <EEPROM.h>
This effectively triggers the Arduino build process to link those libraries into the final executable file.
Related, my reply in this thread: Classes and objects: how many and which file types do I actually need to use them?
-
Thanks, that seems to be working in the Arduino IDE, but where I really need it to work is using the Visual Micro visual studio addin. When I compile the project there I get
#fatal error: SPI.h: No such file or directory
so it doesn't seem to be handling the library paths correctly.– BobCommented Jan 15, 2016 at 20:47 -
1
As you have found, Visual Micro will not consider the project to be an Arduino project if you do not have a "project_name.ino" included in the project
A cheat is to create a "project_name.cpp" and include it in the project. This will cause the .ino to be ignored during compilation.
EDIT: The project_name.cpp takes priority during compile, therefore the .ino just becomes a dummy. However the .ino will still be used for intellisense. The cpp should be #included in the .ino along with any libraries you want discovered by intellisense.
The Visual Micro release yesterday includes automatic "library in library" discovery which means you would no longer need to put all lib #include's in the project_name.ino. (tip: you can switch the "deep search" feature off for each project via the Visual Micro menu. It slows the compile down with large libraries)
-
Just to clarify, if "deep search" is off would the #includes still need to be in the .ino files?– BobCommented Jan 16, 2016 at 7:57
-
1Yes. With "Deep Search Off" all possible library includes need to be in the master .ino file. Then deep search is pointless :) Commented Jan 16, 2016 at 19:40