c++ - 如何使用makefile编译arduino核心库?

标签 c++ c makefile arduino avr-gcc

我想使用makefile创建arduino核心库的库文件(.a),最终还有其他库(SPI,...),但我无法让它工作!

这是我的 makefile:

CC=avr-gcc
CPP=avr-g++
MCU=-mmcu=atmega328p
CPU_SPEED=-DF_CPU=16000000UL
CFLAGS=$(MCU) $(CPU_SPEED) -g2 -gstabs -Os -Wall \
-ffunction-sections -fdata-sections -fno-exceptions
INCLUDE=-I./arduinoCORE

CFILES=$(wildcard ./arduinoCORE/*.c)
CPPFILES=$(wildcard ./arduinoCORE/*.cpp)

OBJ=$(CFILES:.c=.o) $(CPPFILES:.cpp=.o)

default: $(OBJ)
    avr-ar -r libarduinoUNO.a $^

%.o : %.c
    $(CC) $< $(CFLAGS) -c -o $@

%.o : %.cpp
    $(CPP) $< $(CFLAGS) -c -o $@

(所有头文件和源文件都在arduinoCORE中;甚至pins_arduino.h)

在 arduinoCORE 上面的目录中执行 $ make 之后,我收到此错误消息:

avr-g++ arduinoCORE/CDC.cpp -mmcu=atmega328p -DF_CPU=16000000UL -g2 -gstabs -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions -c -o arduinoCORE/CDC.o
In file included from arduinoCORE/Print.h:27:0,
                 from arduinoCORE/Stream.h:26,
                 from arduinoCORE/HardwareSerial.h:28,
                 from arduinoCORE/Arduino.h:193,
                 from arduinoCORE/Platform.h:15,
                 from arduinoCORE/CDC.cpp:19:
arduinoCORE/Printable.h:23:17: fatal error: new.h: No such file or directory
 #include <new.h>
                 ^
compilation terminated.

make: *** [arduinoCORE/CDC.o] Error 1  

问题是,new.h实际上在arduinoCORE中! 有谁知道如何管理这个吗?

最佳答案

我的代码出现了不同的错误。它显示 Arduino.h 不存在。我在将 INCLUDE 变量实际添加到 CFLAGS 和 CPPFLAGS 后修复了它(您的已定义但未添加)。

我还按照 Arduino Specification 使用了 CFLAGS 和 CPPFLAGS 。代码是:

CC=avr-gcc
CPP=avr-g++
MCU=-mmcu=atmega328p
CPU_SPEED=-DF_CPU=16000000UL
INCLUDE=-I./

CFLAGS = -c -g -Os -w -ffunction-sections -fdata-sections -MMD $(MCU) $(CPU_SPEED) $(INCLUDE) 
CPPFLAGS = -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD $(MCU) $(CPU_SPEED)  $(INCLUDE)

CFILES=$(wildcard ./*.c)
CPPFILES=$(wildcard ./*.cpp)

OBJ=$(CFILES:.c=.o) $(CPPFILES:.cpp=.o)

default: $(OBJ)
    avr-ar rcs core.a $^

%.o : %.c
    $(CC) $< $(CFLAGS) -c -o $@

%.o : %.cpp
    $(CPP) $< $(CPPFLAGS) -c -o $@

这成功创建了存档(未经测试,刚刚创建)。

关于c++ - 如何使用makefile编译arduino核心库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32063073/

相关文章:

c - OpenCL 2 维工作项顺序?

emacs 自定义 C++ 编译支持

makefile - 使 "make"默认为 "make -j 8"

c++ - 如何处理 QThread 上的事件?

c++ - 将 MinGw 编译器集成到 Dev C++ 中

c++ - 在 Vista 上清除 Listview 标题图像时出现问题

c - 龟兔赛跑指南

c - 从无符号到有符号的转换是否未定义?

c++ - C++ 变量的定义,Basic/6 部分

c++ - 当我尝试编译时带有 boost 的 undefined reference