Want to compile sketches without the Arduino IDE

Hi all,

As the title says, I wish to compile sketches without using the Arduino IDE.

I already read the section on how to do it (Arduino "Build Process") and I think I'm close... the problem I'm running into now is the compiler not finding the libraries.

Here's a test sketch I'm using:

File: test.cpp

#include <Arduino.h>

#define uno.build.mcu atmega328p // from boards.txt
#define uno.build.f_cpu 16000000L
#define uno.build.core arduino
#define uno.build.variant standard

void setup(void)
{
        Serial.begin(9600);
}

void loop(void)
{
        Serial.print("It works!\r\n");
        delay(1000);
}

To compile the file, I run "make" and use a generic Makefile (with the proper filename inserted for the CPP file).

This is the error I get:

test.cpp:1:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
make: *** [test.o] Error 1

And I suspect it's because of an error in the Makefile:

List any extra directories to look for include files here.

For a directory that has spaces, enclose it in quotes.

EXTRAINCDIRS += "/usr/share/arduino-1.0.2/libraries"
EXTRAINCDIRS += "/usr/share/arduino-1.0.2/hardware/arduino/cores/arduino"

Anyone have any ideas? Are there other library directories I need to point to?

Any help will be appreciated. Thanks!

-- Roger

Which operating system are you using?

dc42:
Which operating system are you using?

Linux (Ubuntu 64 bit).

In that case, I would expect Arduinio.h to be in directory "/usr/share/arduino-1.0.2/hardware/arduino/cores/arduino". Is it?

dc42:
In that case, I would expect Arduinio.h to be in directory "/usr/share/arduino-1.0.2/hardware/arduino/cores/arduino". Is it?

Yes it is, and I pointed to it in the Makefile (see post #1). That's what has me confused.

How is EXTRAINCDIRS used? I've never seen += used in a makefile - are you sure it has the desired effect?

dc42:
How is EXTRAINCDIRS used? I've never seen += used in a makefile - are you sure it has the desired effect?

No, I'm not sure at all.

I just took a makefile from another project and modified it to my needs. I guess I didn't do it correctly.

I've tried all kinds of things. I've even used "#include /usr/share/whole/darn/path/to/library.h" in the source and it still fails.

So that's what I am trying to do... figure out how to compile a sketch without using the Arduino IDE.

As it is, I edit the source with NANO, then click the "upload" button on a very tiny Arduino IDE stuffed up in the corner of my screen. I'd like to get rid of it altogether and use a "real" IDE (oops I know that will bring some wrath down upon me!) :slight_smile:

There are already several variants of a makefile that have been written to do just what you are (re)doing. I believe they all branch from a version by Martin Oldfield, which in turn stems from a version that actually came with earlier versions if the IDE (but is no longer officially supported.)

I use Martin Oldfield's current version with success. I use Emacs as my editor, and use the M-x compile cmd to invoke the makefile from within Emacs. The compiler warnings/error messages pop up in their own window, as usual, and clicking on any message will take you directly to that line in the file. So a bit more IDE than the "official" IDE, I guess, and certainly a better editor, but if you want integrated hardware debugging, you have to go to an Atmel product and their supporting hardware, at least at this stage. The debugging protocols are proprietary, and they're not telling, apparently.

I haven't tried any of the other variants available, so I can't really comment on relative advantages/disadvantages, but Martin Oldfield's version works fine for me.

Krupski, if you post the makefile then it will be easier to provide help.

Might be good ideas in this one, too: ::[ edam ]:: ยป Arduino Makefile

-br

Thank you all (especially PICO). The Makefile by Martin Oldfield worked perfectly. More importantly, it showed me what STEPS need to be done to make "bare" Arduino code compilable.

I've got it all working. Thanks again to all!

-- Roger