【问题标题】:make: *** No rule to make target `main.o'make: *** 没有规则来制作目标“main.o”
【发布时间】:2011-08-07 18:52:21
【问题描述】:

这是 Eclipse 控制台的输出:

 **** Build of configuration Debug for project FatFstest ****

make all 
make: *** No rule to make target `main.o', needed by `FatFstest.elf'.  Stop.

我正在尝试使用 Eclipse 的 AVR 插件构建一个项目来测试 FatFs 库。我首先导入了 FatFs 代码,然后创建了 main.c 文件来实现它。在我第一次尝试构建它之后,我将我的项目的 src 文件夹添加到我的 Properties > AVR Compiler > Directories 中的目录列表中,但我仍然收到构建错误。有什么帮助吗?

这是我的生成文件:

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include src/subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_DEPS)),)
-include $(S_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 
LSS += \
FatFstest.lss \

SIZEDUMMY += \
sizedummy \

AVRDUDEDUMMY += \
avrdudedummy \


# All Target
all: FatFstest.elf secondary-outputs

# Tool invocations
FatFstest.elf: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: AVR C Linker'
    avr-gcc -Wl,-Map,FatFstest.map -mmcu=atmega328p -o"FatFstest.elf" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

FatFstest.lss: FatFstest.elf
    @echo 'Invoking: AVR Create Extended Listing'
    -avr-objdump -h -S FatFstest.elf  >"FatFstest.lss"
    @echo 'Finished building: $@'
    @echo ' '

sizedummy: FatFstest.elf
    @echo 'Invoking: Print Size'
    -avr-size --format=avr --mcu=atmega328p FatFstest.elf
    @echo 'Finished building: $@'
    @echo ' '

avrdudedummy: FatFstest.elf
    @echo 'Invoking: AVRDude'
    /usr/local/CrossPack-AVR-20100115/bin/avrdude -pm328p -Uflash:w:FatFstest.hex:a
    @echo 'Finished building: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM) $(OBJS)$(C_DEPS)$(ASM_DEPS)$(ELFS)$(LSS)$(AVRDUDEDUMMY)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS) FatFstest.elf
    -@echo ' '

secondary-outputs: $(LSS) $(SIZEDUMMY) $(AVRDUDEDUMMY)

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

main.c

#include <diskio.h>
#include <ff.h>
#include <stdio.h>
 int main(void)
 {
   printf("hello world\n");
   return 0;
 }

子目录.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

# Add inputs and outputs from these tool invocations to the build variables 
C_SRCS += \
../src/diskio.c \
../src/ff.c \
../src/main.c 

OBJS += \
./src/diskio.o \
./src/ff.o \
./src/main.o 

C_DEPS += \
./src/diskio.d \
./src/ff.d \
./src/main.d 


# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
    @echo 'Building file: $<'
    @echo 'Invoking: AVR Compiler'
    avr-gcc -I"/Users/nathannewcomb/Documents/Puzzles/FatFstest/src" -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o"$@" "$<"
    @echo 'Finished building: $<'
    @echo ' '

objects.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS :=

sources.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

O_SRCS := 
C_SRCS := 
S_UPPER_SRCS := 
S_SRCS := 
OBJ_SRCS := 
ASM_SRCS := 
OBJS := 
C_DEPS := 
ASM_DEPS := 
ELFS := 
LSS := 
AVRDUDEDUMMY := 
S_DEPS := 
SIZEDUMMY := 
S_UPPER_DEPS := 

# Every subdirectory with source files must be described here
SUBDIRS := \
src \

【问题讨论】:

  • 您能否通过将您的makefile 减少到引发问题所需的最小 来隔离问题?目前,我们看不到所有这些包含的内容,等等。
  • 检查 $(OBJS) 或 $(USER_OBJS) 是否有规则将 main.cc 编译为 main.o。只需在包含的所有 make 文件中搜索“main”并跟踪编译“树”,以便它可以构建 main.o。也许您必须添加一条规则!
  • @Oli 对不起。我刚刚发布了eclipse自动生成的makefile。你能更具体地说明你想要什么吗?我很困惑。
  • @Nathan:我的意思是,makefile 太复杂了,这里的任何人都无法在不访问它使用的所有包含文件的情况下进行调试,也无法访问您的环境。最好的办法是手动编辑 makefile 以找出问题的原因。
  • 我看到您现在已经发布了包含文件的内容。我有点困惑,因为$(OBJS) 包含./src/main.o,但您发布的错误消息仅涉及main.o(没有其余路径)。

标签: eclipse makefile avr


【解决方案1】:

我也遇到过这种情况,只需将 main.cpp 移动到另一个文件夹中。

我尝试清理项目,但问题仍然存在,所以我删除了Debug文件夹,重新编译它可以工作!

【讨论】:

  • 应该被接受,因为这是问题所在,Debug目录缓存了一个makefile,它需要在源文件移动后重建。
【解决方案2】:

不要把main.c放在一个目录下,把它放在它的项目的顶部

【讨论】:

    【解决方案3】:

    我将项目的 src 文件夹添加到我的目录列表中 属性 > AVR 编译器 > 目录

    删除此/Users/nathannewcomb/Documents/Puzzles/FatFstest/src 文件夹并尝试重新编译。

    在 subdir.mk 文件中,行:

    avr-gcc -I"/Users/nathannewcomb/Documents/Puzzles/FatFstest/src" -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o"$@" "$<"
    

    应该变成:

    avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o"$@" "$<"
    

    src 文件夹已添加到 source.mk 文件中:

    # Every subdirectory with source files must be described here
    SUBDIRS := \
    src \
    

    【讨论】:

      【解决方案4】:

      引用 eclipse - http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Fconcepts%2Fcdt_c_makefile.htm

      第二季度。我的控制台视图显示没有规则将目标设为“X”。

      make -k 清除所有 make: * 没有使目标“干净”的规则。 make: * 没有将目标设为“全部”的规则。 默认情况下,make 程序会查找最常称为“Makefile”或“makefile”的文件。如果它在工作目录中找不到这样的文件,或者该文件为空或该文件不包含命令行目标的规则(在这种情况下为“clean”和“all”),它通常会失败并出现错误类似于显示的消息。

      如果您已经有一个有效的 Makefile,您可能需要更改构建的工作目录。 build 命令的默认工作目录是项目的根目录。您可以通过在 Make Project 属性中指定备用构建目录来更改此设置。或者,如果您的 Makefile 被命名为其他名称(例如 buildFile.mk),您可以通过将默认 Build 命令设置为 make -f buildFile.mk 来指定名称。

      如果您没有有效的 Makefile,请在根目录中创建一个名为 Makefile 的新文件。然后,您可以添加示例 Makefile(如上)的内容,并根据需要进行修改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-14
        • 2015-09-26
        • 1970-01-01
        • 1970-01-01
        • 2021-05-12
        • 2023-02-25
        • 1970-01-01
        • 2014-06-13
        相关资源
        最近更新 更多