У меня есть проект, который легко компилируется в Windows с помощью make
, но не работает в Linux. Не получается при неявной компиляции в объектные файлы (выложу отрывок):
arm-none-eabi-gcc -Wl,-Map=All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/List
/PMSCounter.map -Wl,--gc-sections -Wl,-T../../linkerScr/atsamr21g18a.ld -mthumb -nostartfiles -mcpu=cortex-m0plus All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/PMSCounterSensor.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/SZ_DbgLib.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/WSNVisualizer.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/WSNMessageSender.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/WSNCommandHandler.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/WSNRouter.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/WSNDemoApp.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsMemAccess.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsTimer.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsMem.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsWriteData.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsCrcService.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsInit.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsEvents.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/stdPdsDataServer.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/fakePds.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/wlPdsTypesConverter.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/wlPdsTaskManager.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/wlPdsSecurity.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/wlPdsInit.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/wlPdsDataServer.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/S_Nv.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/S_XNv.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/D_XNv-SamR21.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/S_Nv-External.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/D_Nv.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/S_Nv_Stub.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysIdleHandler.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysSleep.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysStat.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysEventsHandler.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysQueue.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysUtils.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysAssert.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysDuplicateTable.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysInit.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysTaskManager.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/dbg.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysMutex.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/sysTimer.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspUsart.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/MaxL.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspTempSensor.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/buttons.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/fakeBSP.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/lcd.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/xyl2rgb.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/joyStick.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspUid.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspI2c.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspVoltageSensor.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspTaskManager.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/hs2xy.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/leds.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/bspSpi.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/csPersistentMem.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/csMem.o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/configServer.o -Wl,-\( ../../../../BitCloud/lib/libBc_All_Atsamr21g18a_Rf233_Gcc.a ../../../../BitCloud/lib/libHAL_SamR21_Atsamr21g18a_8Mhz_Gcc.a -Wl,-\) -o All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Exe/PMSCounter.elf
arm-none-eabi-gcc: error: All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Obj/configServer.o: No such file or directory
arm-none-eabi-gcc: error: ../../../../BitCloud/lib/libHAL_SamR21_Atsamr21g18a_8Mhz_Gcc.a: No such file or directory
Makefile_All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc:172: recipe for target 'All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Exe/PMSCounter.elf' failed
make[1]: *** [All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc/Exe/PMSCounter.elf] Error 1
make[1]: Leaving directory '/mnt/Data/Work_Senzopt/PMS/Codebase/Main_codebase/parking-counter/parking-counter-2/parking-counter-2/Applications/PMSCounter/makefiles/ATSAMR21G18A'
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 2
Я пробовал делать make -nd
как в Windows, так и в Linux, и первое, что происходит в Windows, - это все файлы * .o, тогда как в Linux он напрямую переходит к этапу связывания. Однако я не понимаю, почему это происходит, потому что, глядя на make-файл, я не могу распознать зависимости платформы. Буду признателен за любые подсказки о том, что я делаю неправильно, спасибо! Мой make-файл:
COMPONENTS_PATH = ../../../../BitCloud/Components
CONFIG_NAME = All_SamR21_Atsamr21g18a_Rf233_8Mhz_Gcc
LIST_PATH = $(CONFIG_NAME)/List
EXE_PATH = $(CONFIG_NAME)/Exe
OBJ_PATH = $(CONFIG_NAME)/Obj
include ../../../../BitCloud/lib/Makerules_Atsamr21g18a_Gcc
DEFINES = \
-DBOARD_SAMR21 \
-DAT86RF233 \
-DATSAMR21G18A \
-DHAL_8MHz \
-DNO_SECURITY_MODE \
-DSTACK_TYPE_ALL
INCLUDES = \
-I../.. \
-I../../include \
-I../../../../BitCloud/Components/BSP/SAMR21/include \
-I../../../../BitCloud/Components/SystemEnvironment/include \
-I../../../../BitCloud/lib \
-I../../../../BitCloud/Components/HAL/include \
-I../../../../BitCloud/Components/BSP \
-I../../../../BitCloud/Components/BSP/include \
-I../../../../BitCloud/Components/NWK/include \
-I../../../../BitCloud/Components/NWK/include/private \
-I../../../../BitCloud/Components/ZDO/include \
-I../../../../BitCloud/Components/ZDO/include/private \
-I../../../../BitCloud/Components/APS/include \
-I../../../../BitCloud/Components/APS/include/private \
-I../../../../BitCloud/Components/SystemEnvironment/include \
-I../../../../BitCloud/Components/ConfigServer/include \
-I../../../../BitCloud/Components/ConfigServer/include/private \
-I../../../../BitCloud/Components/PersistDataServer/include \
-I../../../../BitCloud/Components/PersistDataServer/std/include \
-I../../../../BitCloud/Components/PersistDataServer/wl/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Types/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Util/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Timer/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Task/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_ErrH/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Log/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Memory/include \
-I../../../../BitCloud/Components/ZLLPlatform/Infrastructure/N_Init/include \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/S_Nv/include \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/S_XNv/include \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/D_Nv/include \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/D_XNv/include \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/D_XNv/src \
-I../../../../BitCloud/Components/ZLLPlatform/ZLL/S_XNv/src \
-I../../../../BitCloud/Components/Security/TrustCentre/include \
-I../../../../BitCloud/Components/Security/ServiceProvider/include \
-I../../../../BitCloud/Components/HAL/drivers/include \
-I../../../../BitCloud/Components/HAL/drivers/VCP/include \
-I../../../../BitCloud/Components/HAL/cortexm0+/atsamr21/common/include \
-I../../../../BitCloud/Components/MAC_PHY/include \
-I../../../../BitCloud/Components/MAC_PHY/MAC_ENV/include \
-I../../../../BitCloud/Components/MAC_PHY/MAC_HWI/include \
-I../../../../BitCloud/Components/MAC_PHY/MAC_HWD_PHY/include \
-I../../../../BitCloud/Components/MAC_PHY/MAC_HWD_PHY/RF231_RF212/PHY/include \
-I../../../../BitCloud/Components/MAC_PHY/MAC_HWD_PHY/RF231_RF212/MAC_HWD/include
LIBS = \
../../../../BitCloud/lib/libBc_All_Atsamr21g18a_Rf233_Gcc.a \
../../../../BitCloud/lib/libHAL_SamR21_Atsamr21g18a_8Mhz_Gcc.a
SRCS = \
../../src/PMSCounterSensor.c \
../../src/SZ_DbgLib.c \
../../src/WSNVisualizer.c \
../../src/WSNMessageSender.c \
../../src/WSNCommandHandler.c \
../../src/WSNRouter.c \
../../src/WSNDemoApp.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsMemAccess.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsTimer.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsMem.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsWriteData.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsCrcService.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsInit.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsEvents.c \
../../../../BitCloud/Components/PersistDataServer/std/src/stdPdsDataServer.c \
../../../../BitCloud/Components/PersistDataServer/src/fakePds.c \
../../../../BitCloud/Components/PersistDataServer/wl/src/wlPdsTypesConverter.c \
../../../../BitCloud/Components/PersistDataServer/wl/src/wlPdsTaskManager.c \
../../../../BitCloud/Components/PersistDataServer/wl/src/wlPdsSecurity.c \
../../../../BitCloud/Components/PersistDataServer/wl/src/wlPdsInit.c \
../../../../BitCloud/Components/PersistDataServer/wl/src/wlPdsDataServer.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/S_Nv/src/S_Nv.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/S_XNv/src/S_XNv.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/D_XNv/src/D_XNv-SamR21.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/S_Nv/src/S_Nv-External.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/D_Nv/src/D_Nv.c \
../../../../BitCloud/Components/ZLLPlatform/ZLL/S_Nv/src/S_Nv_Stub.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysIdleHandler.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysSleep.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysStat.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysEventsHandler.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysQueue.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysUtils.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysAssert.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysDuplicateTable.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysInit.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysTaskManager.c \
../../../../BitCloud/Components/SystemEnvironment/src/dbg.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysMutex.c \
../../../../BitCloud/Components/SystemEnvironment/src/sysTimer.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspUsart.c \
../../../../BitCloud/Components/BSP/SAMR21/src/MaxL.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspTempSensor.c \
../../../../BitCloud/Components/BSP/SAMR21/src/buttons.c \
../../../../BitCloud/Components/BSP/SAMR21/src/fakeBSP.c \
../../../../BitCloud/Components/BSP/SAMR21/src/lcd.c \
../../../../BitCloud/Components/BSP/SAMR21/src/xyl2rgb.c \
../../../../BitCloud/Components/BSP/SAMR21/src/joyStick.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspUid.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspI2c.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspVoltageSensor.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspTaskManager.c \
../../../../BitCloud/Components/BSP/SAMR21/src/hs2xy.c \
../../../../BitCloud/Components/BSP/SAMR21/src/leds.c \
../../../../BitCloud/Components/BSP/SAMR21/src/bspSpi.c \
../../../../BitCloud/Components/ConfigServer/src/csPersistentMem.c \
../../../../BitCloud/Components/ConfigServer/src/csMem.c \
../../../../BitCloud/Components/ConfigServer/src/configServer.c
PREINCLUDE = MakerulesBc_All_Atsamr21g18a_Rf233_Gcc.h
CSRCS = $(filter %.c, $(SRCS))
OBJS = $(addprefix $(OBJ_PATH)/, $(notdir %/$(subst .c,.o,$(CSRCS))))
ASM_FILE_EXT = s
ifneq (, $(findstring .$(ASM_FILE_EXT), $(SRCS)))
ASRCS = $(filter %.$(ASM_FILE_EXT), $(SRCS))
OBJS += $(addprefix $(OBJ_PATH)/, $(notdir %$(subst .$(ASM_FILE_EXT),.o,$(ASRCS))))
endif
CFLAGS += $(DEFINES)
CFLAGS += $(INCLUDES)
CFLAGS += --include $(PREINCLUDE)
CFLAGS += -g
ASFLAGS = $(INCLUDES)
ASFLAGS += $(filter -mcpu%,$(CFLAGS))
$(OBJ_PATH)/%.o: $(SRCS)
$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -o $@
LD = $(CC)
LINKER_FLAGS = -Wl,-Map=$(LIST_PATH)/$(APP_NAME).map -Wl,--gc-sections
LINKER_FLAGS += -Wl,-T../../linkerScr/atsamr21g18a.ld
LINKER_FLAGS += -mthumb -nostartfiles
LINKER_FLAGS += $(filter -mcpu%,$(CFLAGS))
.PHONY: all directories clean size root_files images
images: $(EXE_PATH)/$(APP_NAME).elf $(EXE_PATH)/$(APP_NAME).hex $(EXE_PATH)/$(APP_NAME).srec $(EXE_PATH)/$(APP_NAME).bin
all: directories images root_files size
$(OBJS): directories
$(EXE_PATH)/$(APP_NAME).elf: $(OBJS)
echo $(OBJS)
$(LD) $(LINKER_FLAGS) $(OBJS) -Wl,-\( $(LIBS) -Wl,-\) -o $@
$(EXE_PATH)/$(APP_NAME).srec: $(EXE_PATH)/$(APP_NAME).elf
$(OBJCOPY) -O srec --srec-len 128 $^ $@
$(EXE_PATH)/$(APP_NAME).hex: $(EXE_PATH)/$(APP_NAME).elf
$(OBJCOPY) -O ihex -R .eeprom $^ $@
$(EXE_PATH)/$(APP_NAME).bin: $(EXE_PATH)/$(APP_NAME).elf
$(OBJCOPY) -O binary --strip-debug --strip-unneeded -R .eeprom $^ $@
root_files: images
cp -f $(EXE_PATH)/*.* ./../../
clean:
rm -rf $(CONFIG_NAME) ../../$(APP_NAME).elf ../../$(APP_NAME).hex ../../$(APP_NAME).srec ../../$(APP_NAME).bin
directories:
@"mkdir" -p $(LIST_PATH)
@"mkdir" -p $(EXE_PATH)
@"mkdir" -p $(OBJ_PATH)
size: $(EXE_PATH)/$(APP_NAME).elf
@echo
@$(SIZE) -td $(EXE_PATH)/$(APP_NAME).elf
ifeq ($(MAKECMDGOALS), fresh)
directories: clean
endif
fresh: all
# eof Makefile
Привет, Юджин, извините за путаницу, я добавил сообщение об ошибке, чтобы было понятно.
Что произойдет, если вы попытаетесь создать "$ (EXE_PATH) / $ (APP_NAME) .elf"?
Удивительно, что это работает в Windows. Есть ряд проблемных моментов в этом make-файле. Один:
OBJS = $(addprefix $(OBJ_PATH)/, $(notdir %/$(subst .c,.o,$(CSRCS))))
Это смущает. notdir
ничего не делает с шаблонами, поэтому добавление %/
(только к первому аргументу!) Ничего не делает. Также использование subst
не является хорошей идеей, потому что он изменяет каждый экземпляр .c
, даже если он появляется в середине файла; например, ../x.comp.c
изменится на ../x.oomp.o
. Эта строка должна быть:
OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(CSRCS)))
Далее, это неправильно:
$(OBJ_PATH)/%.o: $(SRCS)
$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -o $@
Это делает каждый объектный файл зависимым от все исходных файлов, поэтому, если вы измените какой-либо исходный файл, каждый объектный файл будет перестроен. С таким же успехом вы можете просто создать сценарий оболочки, а не использовать make. Вот почему вам нужно пройти через рецепт, чтобы найти файл C, который вы хотите скомпилировать. Лучше бы использовать VPATH. Также вам необходимо иметь опцию -c
в вашей строке компилятора для создания объектных файлов ... Я не вижу, чтобы он был добавлен в ваш CFLAGS
, но лучшие практики все равно не помещают его туда:
vpath %.c $(sort $(dir $(CSRCS)))
$(OBJ_PATH)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
Далее эта строка не годится:
$(OBJS): directories
Это будет перестраивать все объекты всякий раз, когда необходимо перестроить цель directories
, что всегда происходит потому, что ни одно правило никогда не создает эту цель: цель directories
никогда не создает файл с именем directories
, поэтому он всегда устарел.
При этом я не могу объяснить ошибку, которую вы видите. Компоновщик жалуется на файл, которого не существует, но этот файл (по-видимому) является предварительным условием для цели, что означает, что если он не существует, make попытается создать его или пожалуется, если не сможет.
После исправления вашего make-файла я рекомендую запустить make -d
(перенаправить в файл, так как вывод будет значительным), найдите цель configServer.o
и посмотрите, что make об этом скажет.
Эй, это отличные комментарии, большое спасибо. Я только что умеренно изменил make-файл, который Atmel предоставляет с Bitcloud, так что проблемы с манипуляциями с именами я знал и планировал исправить в ближайшее время. Вчера вечером я сделал именно то, что вы сказали: я взял make -d
как из windows, так и из linux, и начал разбираться в обоих. Скоро буду обновлять то, что я найду.