Godhaze
Godhaze

Reputation: 155

Arduino makefile can't compile

I'm trying to compile my Arduino file/project with Makefile. But I'm having issues with the global variables. It says there not declared. The makefile that I downloaded was from github: https://github.com/sudar/Arduino-Makefile.

Since I have no experience about Arduino, I don't see what could be the problem.

My error code:

    -------------------------
    Arduino.mk Configuration:
    - [AUTODETECTED] CURRENT_OS = LINUX
    - [COMPUTED] ARDMK_DIR = /usr/share/arduino (relative to Common.mk)
    - [USER] ARDUINO_DIR = /usr/share/arduino
    - [AUTODETECTED] ARDUINO_VERSION = 105
    - [DEFAULT] ARDUINO_SKETCHBOOK = /sketchbook
    - [BUNDLED] AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino distribution)
    - [COMPUTED] ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
    - [DEFAULT] ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/cores/arduino
    - [COMPUTED] ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/variants (from ARDUINO_DIR)
    - [COMPUTED] BOARDS_TXT = /usr/share/arduino/hardware/arduino/boards.txt (from ARDUINO_DIR)
    - [DEFAULT] USER_LIB_PATH = /sketchbook/libraries (in user sketchbook)
    - [USER] BOARD_TAG = uno
    - [COMPUTED] OBJDIR = build-uno (from BOARD_TAG)
    - [ASSUMED] MONITOR_BAUDRATE = 9600
    - [DEFAULT] OPTIMIZATION_LEVEL = s
    - [DEFAULT] MCU_FLAG_NAME = mmcu
    - [DEFAULT] CFLAGS_STD = -std=gnu99
    - [AUTODETECTED] Size utility: AVR-aware for enhanced output
    -
    - ARDUINO_LIBS =
    - [SYSTEM] Wire
    - [SYSTEM] EEPROM
    - [SYSTEM] Esplora
    - [SYSTEM] Ethernet
    - [SYSTEM] Firmata
    - [SYSTEM] GSM
    - [SYSTEM] LiquidCrystal
    - [SYSTEM] Robot_Control
    - [SYSTEM] Robot_Motor
    - [SYSTEM] SD
    - [SYSTEM] Servo
    - [SYSTEM] SoftwareSerial
    - [SYSTEM] SPI
    - [SYSTEM] Stepper
    - [SYSTEM] TFT
    - [SYSTEM] WiFi
    - [SYSTEM] Wire
    - [SYSTEM] Wire/utility
    - [SYSTEM] Ethernet/utility
    - [SYSTEM] Robot_Control/utility
    - [SYSTEM] SD/utility
    - [SYSTEM] TFT/utility
    - [SYSTEM] WiFi/utility
    - [SYSTEM] Wire/utility
    - [COMPUTED] BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino/bootloaders (from ARDUINO_DIR)
    -------------------------
    /usr/share/arduino/hardware/tools/avr/bin/avr-g++ -MMD -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=105 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Wire -I/usr/share/arduino/libraries/EEPROM -I/usr/share/arduino/libraries/Esplora -I/usr/share/arduino/libraries/Ethernet -I/usr/share/arduino/libraries/Firmata -I/usr/share/arduino/libraries/GSM -I/usr/share/arduino/libraries/LiquidCrystal -I/usr/share/arduino/libraries/Robot_Control -I/usr/share/arduino/libraries/Robot_Motor -I/usr/share/arduino/libraries/SD -I/usr/share/arduino/libraries/Servo -I/usr/share/arduino/libraries/SoftwareSerial -I/usr/share/arduino/libraries/SPI -I/usr/share/arduino/libraries/Stepper -I/usr/share/arduino/libraries/TFT -I/usr/share/arduino/libraries/WiFi -I/usr/share/arduino/libraries/Wire -I/usr/share/arduino/libraries/Wire/utility -I/usr/share/arduino/libraries/Ethernet/utility -I/usr/share/arduino/libraries/Robot_Control/utility -I/usr/share/arduino/libraries/SD/utility -I/usr/share/arduino/libraries/TFT/utility -I/usr/share/arduino/libraries/WiFi/utility -I/usr/share/arduino/libraries/Wire/utility -Wall -ffunction-sections -fdata-sections -Os -fno-exceptions main.cpp -o build-uno/main.o
    main.cpp: In function 'void setup()':
    main.cpp:17:16: error: 'OUTPUT' was not declared in this scope
    pinMode(led, OUTPUT);
    ^
    main.cpp:17:22: error: 'pinMode' was not declared in this scope
    pinMode(led, OUTPUT);
    ^
    main.cpp: In function 'void loop()':
    main.cpp:23:30: error: 'analogWrite' was not declared in this scope
    analogWrite(led, brightness);
    ^
    main.cpp:33:11: error: 'delay' was not declared in this scope
    delay(30);
    ^
    make: *** [build-uno/main.o] Error 1

Upvotes: 1

Views: 658

Answers (1)

Alexandre Perrin
Alexandre Perrin

Reputation: 459

The Arduino IDE does some "sketch pre-processing" (see https://github.com/arduino/arduino-preprocessor#about-the-arduino-sketch-ino-preprocessing) that Arduino-Makefile does not. In other words, the Arduino IDE modify your sketch.ino to convert it into C++ before attempting to compile it while Arduino-Makefile try to compile it without changes.

As a result, Arduino-Makefile fail to compile some sketch that compile just fine using the Arduino IDE. Performing by hand theses three steps usually do the trick:

  1. Are there many source files? If yes, merge them into a single file.
  2. Is #include <Arduino.h> at the top of the single source file? If not, add it.
  3. Are all functions declared before use? if not, add forward declaration.

In your case, it looks like step 2 is needed (the missing variable OUTPUT and missings functions from your compilation error message are declared in Arduino.h, see https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Arduino.h).

If you intent to continue with Arduino-Makefile I would suggest to get used to theses types of errors as most sketch you will find on the web are only tested using the Arduino IDE. On the bright side, it's usually trivial to convert them into C++ and rarely time consuming as Arduino sketch are rarely "big".

Upvotes: 3

Related Questions