converting .ino files to .cpp

Since .ino files are an arduino thing and I’ve been trying to get as close to standard C++ as I can anticipating the switch out of the arduino environment. I decided to change all my project’s .ino files except the main one to .cpp files. So now I’ve got one .ino, four .cpp and five .h files. My .ino file has a #include for all the .h files.
I started off with a bunch of errors. I don’t fully understand why, but I was able to fix some of them.

  • I had to add what I believe are called forward declarations since some structures and functions are used globally in my project. These are like function prototypes, but for functions in other cpp files.
  • I had a user library which no longer worked with #include “my_lib” but did with #include <my_lib>. Which is odd since I thought <> was just for built in libraries.
  • I had to put all my #includes in my .ino file. This seemed odd, since if A requires B and B requires C, why can’t B import C? Why does A have to import everything that any other file might need. Doesn’t seem much like encapsulation to me.

Now I’ve got a function I use throughout my code to log messages to the SD card. Here’s the prototype:

void log_msgL(unsigned char logLevel,const __FlashStringHelper *format, ... );

I now get an error “ISO C++ forbids declaration of ‘__FlashStringHelper’ with no type” and I have no idea what to do, except go back to all ino files. All the answers on this error I can find talk about namespaces. Will I need to dig thought the arduino code to find how __FlashStringHelper is declared?

So for some reason I stuck

#include <arduino.h>

In my header file even though it was already at the top of the corresponding cpp file, and my errors went away.

Would there have been another way of fixing this?

RyanN: So now I've got one .ino, four .cpp and five .h files. My .ino file has a #include for all the .h files.

Best reason I can think of to stick with .INO files.

...R

RyanN: Would there have been another way of fixing this?

Can't say without seeing all of your code, but what you've ended up doing when you moved back to conventional C++ is replicating the mucking-about that the Arduino IDE does to your .ino files before it compiles it. Once you are using plain old C++ source files the behaviour of C++ is well known and well documented, but whether you got it right or what mistakes you introduced I have no idea. If it compiles and works afterwards it can't be [u]too[/u] bad.