我正在尝试使用Makefile编译我的Arduino文件/项目。但是我遇到了全局变量的问题。它说没有宣布。我下载的makefile来自github:https://github.com/sudar/Arduino-Makefile。
由于我没有Arduino的经验,我不知道可能是什么问题。
我的错误代码:
-------------------------
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
答案 0 :(得分:3)
Arduino IDE做了一些"草图预处理" (参见https://github.com/arduino/arduino-preprocessor#about-the-arduino-sketch-ino-preprocessing)Arduino-Makefile没有。换句话说,Arduino IDE会修改你的sketch.ino,然后在尝试编译它之前将其转换为C ++,而Arduino-Makefile尝试编译它而不做任何更改。
因此,Arduino-Makefile无法编译一些使用Arduino IDE编译得很好的草图。手工执行这三个步骤通常可以解决问题:
#include <Arduino.h>
位于单个源文件的顶部?如果没有,请添加它。在您的情况下,看起来需要第2步(缺少的变量OUTPUT
和编译错误消息中的缺失函数在Arduino.h
中声明,请参阅https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Arduino.h)。
如果您打算继续使用Arduino-Makefile,我建议您习惯这些类型的错误,因为您在Web上找到的大多数草图仅使用Arduino IDE进行测试。从好的方面来说,将它们转换为C ++通常是微不足道的,而且很少耗费时间,因为Arduino草图很少&#34;大&#34;。