3

I'm building an arduino program on linux, using the following Makefile:

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG = uno
ARDUINO_PORT = /dev/ttyAMA0
ARDUINO_LIBS = Wire
include /usr/share/arduino/Arduino.mk

Currently all of my code is spread among a dozen header files and a single .ino file - it gets compiled and it runs properly when flashed. I know that's not correct though and I'm trying to split my code into the proper structure of source and header files but when I do and try to build it I get the following output:

In file included from gear.c:1:0:
gear.h:19:1: error: unknown type name ‘byte’
 byte GEAR = 3;
 ^

Which leads me to believe that the source file is getting compiled separately and does not know what a byte is, which is supposedly defined somewhere within the arduino library.

What's the proper way to build my project with source files?

php_nub_qq
  • 223
  • 3
  • 10

1 Answers1

2

First of all, I recommend you write in C++ (file extension .cpp) rather than in plain C (files in .c). The reason is that the Arduino programming environment is based on C++, some of the libraries are C++-only, and your main .ino file will be compiled as C++ source. Mixing this with C is possible, using some extern "C" declarations, but it is probably more hassle that it's worth.

Now, to answer your actual question, just add thsi near the top of your source files:

#include <Arduino.h>

This includes the type definitions specific to the Arduino environment, together with the core API. This include is added automatically to any file ending in .ino, but you have to add it explicitly to your .cpp files.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81