Including one .ino source in multiple projects WITHOUT a library

Having one source code .ino file with lots of reusable functions, can be a problem if you have many projects that want to share that same code function. Normally the quick hack is to just copy functions code .ino and plonk it into each IDE project folder. But then you have more than one copy of the same source file and things can soon get out of hand, even if you try and adopt good version control. The more appropriate way is to convert your .ino source functions into cpp code and build a library, just like all the others that can be found in the Arduino Libraries folder, like LiquidCrystal etc.

If you are using a MAC, then OS X allows you to do something else, which is far more versatile when you are still prototyping, but using your core functions. The key to this is solution is by using a soft link to the functions .ino code. A soft link is different to a hard link and is also different to an OS X Finder Alias. The way I do this is to have a folder above all my Arduino project folders, which contains normally all my 'shared between all projects' include files (.h's). In this folder I put my .ino reusable function code source file. I then create a soft link via the shell (Terminal), to the .ino code file. I then copy this linked file into all of the required Arduino project folders. My Arduino project folder will then have its regular .ino project source code file, plus this linked file. When you open the Arduino IDE, by clicking on the project source .ino file NOT the linked file, the IDE while display both your project source code and the source code for your reusable functions, in a separate tab. Just be careful not to alter the code in the second new tab (your function code), otherwise the real function code will alter. Oh and just be careful not to open more than one IDE and work on multiple projects at a time, otherwise you may alter your reusable function code accidentally and each IDE, whilst open will be showing a different view of the code (as it was when first opened).

In the OS X shell use this command: ln -s [reusable functions source file (.ino) [destination name]. Where ln is LN in lowercase. There is a man page on it.

cd to '/Users/Willy/Documents/Arduino'

Type in:
ln -s /Users/Willy/Documents/Arduino/myFunctions.ino myProjectFolder/myfunctions.ino

You will then have a soft linked file, which is just a pointer, in your project folder, which is to any software the real function code file. You can copy this linked file to as many other project folders as you wish and they will all see the file and compile without problems.

A word of warning... If this lot makes little sense to you and you do not know much about UNIX, then I would be very careful. And ALWAYS back everything up FIRST.


I just copy the code I want to reuse into the new sketch I am working on.
Something always needs adjusting, or can be improved.