Including INO Files in Arduino Compilation as a Library
Libraries help consolidate code and reuse it across multiple Arduino sketches. However, what if you want to reuse Arduino sketch code/functions? The Arduino Build Process states the following pre-process step:
All .ino files in the sketch folder (shown in the IDE as tabs with no extension) are concatenated together, starting with the file that matches the folder name followed by the others in alphabetical order, and the .cpp extension is added to the filename.
This doesn’t help re-use sketch code, though. I discovered a symlink will allow you to maintain a sketch in a central location and compile it with your sketch in a another location.
-
Place the “library sketch” anywhere you want (let’s call it,
myFunctions.ino)
. -
Open Terminal and create a symlink:
>> ln -s /path/to/sketchfolder myFunctions.ino
Now you should have a symlink in your sketch folder that acts like an actual file. You can edit myFunctions.ino
in a central location and it will compile with the other sketch.
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011