簡體   English   中英

如何用makefile編譯arduino核心庫?

[英]How to compile arduino core library with makefile?

我想使用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規范,我還使用了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 $@

哪個成功創建了歸檔文件(未經測試,剛剛創建)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM