amperka / ino

Command line toolkit for working with Arduino hardware
http://inotool.org
MIT License
1.08k stars 233 forks source link

multiple ino files compiling not working #202

Open Jones-S opened 9 years ago

Jones-S commented 9 years ago

Hi there I'm not sure, if I'm missing out something... But I thought that in my src folder all my ino files would be compiled into one. I have a sketch.ino file with all stuff in it. and now a 2nd ino file for experimenting. that 2nd file has a function called 'printShift()' and that very function I'm calling in the setup of my main file. Unfortunately the terminal tells me:

src/printShift.ino
Scanning dependencies of src
src/sketch.cpp
src/sketch.ino: In function 'void setup()':
src/sketch.ino:47: error: 'printShift' was not declared in this scope
make: *** [.build/uno/src/sketch.o] Error 1
Make failed with code 2

Do you know how I can get multiple ino files to get to work? Thanks for any help on that matter.

Cheers

krisbarrett commented 9 years ago

I am not a contributor, but I have a suggestion. It sounds like printShift() belongs in a library. In the lib directory, create a directory for your library (MyLibrary). Inside of this directory create two files: MyLibrary.h and MyLibrary.cpp. Add the function to MyLibrary.cpp and add a function prototype for it in MyLibrary.h. Inside of sketch.ino add the following line to the top of the file:

#include "MyLibrary.h"

You might also need to include Arduino inside of MyLibrary.cpp:

#include <Arduino.h>

Also, if you are using Serial, you need to tell the compiler that Serial exists outside of your library using the following line:

extern HardwareSerial Serial;

You can find an example of an Arduino library that I am working on here.

Jones-S commented 9 years ago

Thanks for your input. I think a Library would be possible, and I also thought about that, but in my case I have such a simple code and just wanted it to divide from the other code. I don't need the hassle with libs. But I thought if I could compile them all into one file, then why not initiate another ino file. Just wondered wether I was making some mistake or if the ino tool does not support the compiling of multiple ino files. But thanks for your answer anyway. Very much appreciated. Cheers

skorokithakis commented 9 years ago

I also have the same problem. There's no documentation on how this is resolved, unfortunately. Can a core contributor elucidate?

nophead commented 9 years ago

I am not a contributor but in an Arduino sketch you only have one ino file. Other files have to be .cpp or .h.

I use ino to build Marlin and that has lots of files in the project.

tomwhipple commented 9 years ago

It seems that this issue can be worked around by thinking about the project like a C program. That's all well and good, but if that's the approach, why bother with .ino?

If it's useful, I've got an example commit illustrating the workaround.

tomwhipple commented 9 years ago

In general, workaround seems to take the form:

  1. ino preproc src/Look.ino >src/Look.h
  2. Add #ifndef _Look_h guard to Look.h
  3. Add #include "Look.h" to Look.ino
  4. Add additional includes to Look.h. (Probably all project includes could be gathered into a meta header, provided individual headers were properly #ifndef guarded.)
  5. Deal with declarations in need of extern.