eclipse make: *** 没有规则可以制作目标`main.o'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6974969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:24:00  来源:igfitidea点击:

make: *** No rule to make target `main.o'

eclipsemakefileavr

提问by Nathan

here is the output from the console in Eclipse:

这是 Eclipse 控制台的输出:

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

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

I am trying to build a project using the AVR plugin for Eclipse to test the FatFslibrary. I first imported the FatFs code then created main.c file to implement it. After I tried building it the first time, I added the src folder of my project to my the directories list in Properties > AVR Compiler > Directories, and I still get the build error. Any help?

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

Here is my makefile:

这是我的生成文件:

################################################################################
# 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;
 }

subdir.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

对象.mk

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

USER_OBJS :=

LIBS :=

sources.mk

来源.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 \

回答by Luca Davanzo

It happened to me too, simply moving main.cpp in an another folder.

它也发生在我身上,只需将 main.cpp 移动到另一个文件夹中即可。

I try to clean out the project, but the problem persist, so I have deleted Debug folder, re-compile and it works!

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

回答by Karim

Don't put the main.c in a directory, put it at the top of its project

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

回答by Lo?c G.

I added the src folder of my project to my the directories list in Properties > AVR Compiler > Directories

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

Remove this /Users/nathannewcomb/Documents/Puzzles/FatFstest/srcfolder and try to compile again.

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

In the subdir.mk file, the line :

在 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"$@" "$<"

should be become :

应该变成:

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"$@" "$<"

This srcfolder is already added in source.mk file :

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

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

回答by mna

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

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

Q2. My Console view says No rule to make target 'X'.

Q2。我的控制台视图显示没有规则可以制作目标“X”。

make -k clean all make: * No rule to make target 'clean'. make: *No rule to make target 'all'. By default, the make program looks for a file most commonly called "Makefile" or "makefile". If it cannot find such a file in the working directory, or if that file is empty or the file does not contain rules for the command line goals ("clean" and "all" in this case), it will normally fail with an error message similar to those shown.

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

If you already have a valid Makefile, you may need to change the working directory of your build. The default working directory for the build command is the project's root directory. You can change this by specifying an alternate Build Directory in the Make Project properties. Or, if your Makefile is named something else (eg. buildFile.mk), you can specify the name by setting the default Build command to make -f buildFile.mk.

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

If you do not have a valid Makefile, create a new file named Makefile in the root directory. You can then add the contents of the sample Makefile (above), and modify it as appropriate.

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