1

I have a project which compiles swimmingly in windows using make but fails in linux. It's failing during implicit compilation to object files (I'll post an excerpt):

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

I tried doing make -nd in both windows and linux, and the first thing that happens in windows is all the *.o files are generated, while in linux it directly goes to the linking step. However, I am lost as to why that's happening because from looking at the makefile, I can't recognize the platform dependencies. I'd appreciate any hints about what I'm doing wrong, thank you! My makefile is:

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

1 Answers1

0

It's surprising that this works on Windows. There are a number of things that are problematic in this makefile. One:

OBJS = $(addprefix $(OBJ_PATH)/, $(notdir %/$(subst .c,.o,$(CSRCS))))

This is confusing. notdir doesn't do anything with patterns so adding the %/ (only to the first argument!) is not doing anything. Also using subst is not a good idea because it changes every instance of .c even if it appears in the middle of a file; for example ../x.comp.c would change to ../x.oomp.o. This line should be:

OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(CSRCS)))

Next, this is not right:

$(OBJ_PATH)/%.o: $(SRCS)
        $(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -o $@

This makes every object file depend on all the source files, so if you change any source file every object file will be rebuilt. You might as well just create a shell script rather than using make. That's why you have to go through contortions in the recipe to find the C file you want to compile. Better would be to use VPATH. Also you need to have the -c option in your compiler line to build object files... I can't see it added to your CFLAGS but best practice doesn't put it there anyway:

vpath %.c $(sort $(dir $(CSRCS)))
$(OBJ_PATH)/%.o: %.c
        $(CC) $(CFLAGS) -c $< -o $@

Next, this line is not good:

$(OBJS): directories

This will rebuild all objects whenever the directories target needs to be rebuilt, which is always because no rule ever creates that target: the directories target never creates a file named directories so it's always out of date.

All that being said, I can't explain the error you're seeing. The linker is complaining about a file that doesn't exist, but that file is (apparently) a prerequisite of the target which means if it didn't exist then make would try to create it, or complain if it couldn't.

After fixing your makefile I recommend running make -d (redirect to a file since the output will be significant) and search for the configServer.o target and see what make has to say about it.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Hey, those are some great comments, thanks a lot. I had just moderately modified the makefile that Atmel gives with Bitcloud, so the problems with name manipulation, I knew of and have planned to improve soon. Last night I did exactly the thing you said, I took the `make -d` from both windows and linux and started going through the diff of both. Will update soon on what I find. – Adeesh Lemonickous May 03 '18 at 05:04