Sketches With Multiple Files

I've tried several time to create sketches that consist of multiple files (other than libraries). I've read numerous web pages about this, but the information I've seen is both conflicting, and doesn't seem to work. The most common advise seems to be to give these files no extension, and the tools will automatically suck them all up, concatenate them into a single file, pre-pend prototypes, etc. Only trouble is, I've been completely unable to make it work. I have to manually add prototypes to my top-level include file.

What am I missing? How is this supposed to work?

I'm using both v1.05 and v1.5.6r2.

Regards, Ray L.

(deleted)

give it a name (no extention)

Even better is to give it the extension you want (.h, .cpp, .ino, etc.) rather than having it decide what the extension should be.

(deleted)

First, I'm not using the Arduino IDE, but Atmel Studio, with VisualMicro, which uses the Arduino tools for dong builds.

Second, no matter the extension, if I don't put an explicit #include, AND manually put a prototype in my top-level header file, it DOES NOT compile.

So is this capablility purely dependent upon using the IDE, and having ALL included files open in the IDE?

Regards, Ray L.

First, I'm not using the Arduino IDE, but Atmel Studio, with VisualMicro, which uses the Arduino tools for dong builds.

So, you left a lot out of your first post. You need to ask your Visual Micro question on the Visual Micro forum.

Second, no matter the extension, if I don't put an explicit #include, AND manually put a prototype in my top-level header file, it DOES NOT compile.

That is NOT an Arduino problem.

So is this capablility purely dependent upon using the IDE

No. The suggestions here were made assuming you were using the IDE, since you didn't bother to say otherwise.

Actually, it has NOTHING to do with AtmelStudio or VisualMicro, which simply use the existing Arduino build process. The real problems have to do with the incredible amount of flat-out WRONG information out there (including some given in this thread), and the fact that the Arduino build process is bizarre, to say the least.

First, I found multiple web sites, as well as information given in this thread, telling me that any additional files must have, and here I quote directly, "NO extension". This is flat-out wrong. The files must ALL have a .INO extension.

Second those same sources indicate that all included files, with "no extension" must be opened in tabs in the IDE. This, too, is flat-out WRONG. They must simply be stored in the same directory as the main .ino file.

Third is the fact that the build process operates in a truly bizarre way, that seems to me designed to fail in random ways. It first grabs the main .ino file, which MUST have the same name as the directory it is in. It then appends ALL other .INO files it finds in that directory, and does so IN ALPHABETICAL ORDER of all things, with upper case taking precedence. It then does a less than perfect job of creating prototypes for the functions it finds in all those files. In some cases, for reasons I can't fathom, it will NOT correctly resolve forward references, making it necessary to either MOVE those functions to a file that lands higher in the alphabetical sort order, or manually create a prototype for those functions. The same goes for variable definitions. Very weird indeed....

Regards, Ray L.

Very weird indeed....

Yes. You can "resolve" some of the issues by using .cpp files instead of .ino files. You can "resolve" more of them by creating the function prototypes yourself. You can "resolve" others by naming the .ino files "smartly".

RayLivingston: Actually, it has NOTHING to do with AtmelStudio or VisualMicro, which simply use the existing Arduino build process.

Really, you're quite sure about that?

The Arduino has its own highly idiosyncratic build process which does a considerable amount of mucking around with your code before it passes it to the compiler. Conventional (i.e. non-Arduino) build environments leave out the mucking about and just compile your code as it is. If you write your code expecting to have the Arduino mucking-about done, and then try to build it within an IDE that compiles it as-is, then obviously that is going to lead to errors. If you write your code expecting it to have the mucking-about done, and you stray outside the simplistic coding constructs that the Arduino IDE can cope with correctly, that will also lead to errors.

If you're outgrowing the Arduino stabilisers then you may get on better writing your sketch in proper C++. You can do that either by ditching Arduino and adopting a grown-up IDE, or using .cpp and .h files within the IDE instead of .ino files. When you create a .ino file, you rely on the IDE to mangle that into proper C++ and have to trust and hope that it will get it right.