make error:make(e = 2):系统找不到指定的文件

时间:2016-04-17 16:48:41

标签: c eclipse makefile nrf51

我正在尝试在新的Windows PC上编译一个c项目,但是当我运行make时,我得到了:

D:\Eclipse_Workspace\project>make
#@make -f  makefile -C ./  -e cleanobj
process_begin: CreateProcess(NULL, #@make -f makefile -C ./ -e cleanobj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [all] Fejl 2

在我的另一台PC上,该项目编译得很好。 “Fejl 2”对于“错误2”也是丹麦语,当其余的是英语时,不知道为什么那是丹麦语。

编辑: 这是makefile(它相当长)

PROJECT_NAME := ble_app_hrs_s110_pca10028

export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) ) 

TEMPLATE_PATH = nrf51_sdk/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif

MK := mkdir
RM := rm -rf

#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO := 
else
NO_ECHO := @
endif

# Toolchain commands
CC              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP         := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY         := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE            := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"

#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))

#source common to all targets
C_SOURCE_FILES += \
nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c \
Drivers/NRF51_BLEDriver.c \
(..... a lot more files ....)

#assembly files common to all targets
ASM_SOURCE_FILES  = nrf51_sdk/toolchain/gcc/gcc_startup_nrf51.s

#includes common to all targets
INC_PATHS  = -I Application/
(..... a lot more include paths.......)

OBJECT_DIRECTORY = _build
LISTING_DIRECTORY =$(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY =$(OBJECT_DIRECTORY)

# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )

#flags common to all targets
CFLAGS  = -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF51
CFLAGS += -DS110
CFLAGS += -DBOARD_PCA10028
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O0 -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
#CFLAGS += -flto -fno-builtin

# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys

# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DNRF51
ASMFLAGS += -DS110
ASMFLAGS += -DBOARD_PCA10028
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
#default target - first one defined
#default: clean nrf51422_xxac_s110

#building all targets
all: #clean
    #$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
    $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110 

#target for printing all targets
help:
    @echo following targets are available:
    @echo   nrf51422_xxac_s110
    @echo   flash_softdevice


C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )

ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )

vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)

OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)

nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110
nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
    @echo Linking target: $(OUTPUT_FILENAME).out
    $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize

## Create build directories
$(BUILD_DIRECTORIES):
    echo $(MAKEFILE_NAME)
    $(MK) $@

# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
    @echo Compiling file: $(notdir $<)
    @echo arm-none-eabi-gcc $(CFLAGS) $(INC_PATHS) -c -o $@ $<
    $(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<

# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
    @echo Compiling file: $(notdir $<)
    $(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<


# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
    @echo Linking target: $(OUTPUT_FILENAME).out
    $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out


## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    @echo Preparing: $(OUTPUT_FILENAME).bin
    $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin

## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    @echo Preparing: $(OUTPUT_FILENAME).hex
    $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

finalize: genbin genhex echosize

genbin:
    @echo Preparing: $(OUTPUT_FILENAME).bin
    $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin

## Create binary .hex file from the .out file
genhex: 
    @echo Preparing: $(OUTPUT_FILENAME).hex
    $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

echosize:
    -@echo ""
    $(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    -@echo ""

clean:
    $(RM) $(BUILD_DIRECTORIES)

cleanobj:
    $(RM) $(BUILD_DIRECTORIES)/*.o

flash: $(MAKECMDGOALS)
    @echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
    nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex)

## Flash softdevice
flash_softdevice: 
    @echo Flashing: s110_softdevice.hex
    nrfjprog --reset --program nrf51_sdk/softdevice/s110/hex/s110_softdevice.hex

1 个答案:

答案 0 :(得分:3)

在make中,每个由TAB字符缩进的行(在“配方上下文中”)将作为命令传递给shell。关于此类行的 Nothing 将由make解释,$除外。

特别是对于您而言,#字符在此上下文中并不特殊,并且不会引入make注释行。所以在这条规则中:

all: #clean
        #$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
        $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110 

第一行未被注释掉;它是一个以#字符开头的命令行,make将要求系统运行该命令。很明显,您的系统上不存在这样的命令。

如果你想在make中注释掉配方行,你应该总是把注释字符放在行的开头而不是TAB之后:

all: #clean
#       $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
        $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110