2

How can I compile my code via terminal? I am working on a Chrome app that allows you to write, compile, and upload code to an Arduino, and I need to know this so I can use the command line compiler on my Linux server. Mac or Linux terminal, it doesn't matter.

1
  • I'm not really sure what exactly you need but to compile in the command line you need something like avr-gcc.
    – Kwasmich
    Commented Mar 2, 2017 at 7:58

3 Answers 3

2

Check out platformio.org it's the best solution out there for command line compiling.

1
1

Assuming an AVR-based Arduino, you would need the avr-gcc compiler, the avr-libc and the Arduino libraries. Also avrdude if you want to upload. The only issue is that the commands used for the build process are quite long (lots of options). You can see them by enabling verbose compilation in the IDE. Thus you will probably want some way to automate the whole thing.

There are several options for this. The most straightforward seems to be the arduino-builder command-line tool. This is part of the Arduino project and should ensure maximum compatibility. Otherwise you could use a plain old Makefile. I personally use Sudar Muthu' Makefile. It can be installed on a Debian-based Linux distribution by:

sudo apt install arduino-mk

It is not fully compatible with the classic Arduino build process though: it does automatically include <Arduino.h> into your sketch, but it does not add forward declarations. Some prefer it this way, as the automatic inclusion of forward declarations is somewhat buggy and does not play well with some C++ features.

1

There is an Arduino CLI (command line interface):

https://github.com/arduino/arduino-cli

You use commands such as to access Arduino IDE functions:

arduino-cli compile --fqbn arduino:avr:leonardo sketch

and

arduino-cli upload -pCOM14 --fqbn arduino:avr:leonardo sketch

(obviously port will be different under Linux)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.