编译错误 - 错误:***多个目标模式。停止

发布于 2025-02-03 07:33:50 字数 2215 浏览 2 评论 0原文

我对存储库的一部分的makefile有问题。我已经发布了这个问题,但不知道如何添加一些代码行,所以我在这里尝试。当我运行MAKE时,我会收到以下错误:C:\ Mios32/incruph/makefile/common.mk:143:***多个目标模式。停止。

这是从common.mk文件从第142行到144的代码:

# rule to create .elf file                                 
$(PROJECT_OUT)/$(PROJECT).elf: $(ALL_OBJS)
    @$(CC) $(CFLAGS) $(ALL_OBJS) $(LIBS) $(LDFLAGS) -o$@

我猜这是all_objs的问题,导致这些行以前似乎有效:

# rule to create a .hex and .bin file                                               
%.bin : $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJCOPY) $< -O binary $@
%.hex : $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJCOPY) $< -O ihex $@

# rule to create a listing file from .elf                                          
%.lss: $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJDUMP) -w -h -S -C $< > $@

# rule to create a symbol table from .elf                                          
%.sym: $(PROJECT_OUT)/$(PROJECT).elf
    @$(NM) -n $< > $@

这里有一些与alll_objs的其他行:

# list of all objects                                                            
ALL_OBJS = $(addprefix $(PROJECT_OUT)/, $(THUMB_OBJS) $(THUMB_CPP_OBJS) $(THUMB_AS_OBJS) 
$(ARM_OBJS) $(ARM_CPP_OBJS) $(ARM_AS_OBJS))

# list of all dependency files                                                 
ALL_DFILES = $(ALL_OBJS:.o=.d)

以及project_out和project的其他一些行:

# where should the output files be located                                    
PROJECT_OUT ?= $(PROJECT)_build

# default linker flags                                                            
LDFLAGS += -T $(LD_FILE) -mthumb -u _start -Wl,--gc-section  -Xlinker -M -Xlinker - 
Map=$(PROJECT_OUT)/$(PROJECT).map  -nostartfiles -lstdc++

# default rule                                                                       
all: dirs cleanhex $(PROJECT).hex $(PROJECT_OUT)/$(PROJECT).bin 
$(PROJECT_OUT)/$(PROJECT).lss $(PROJECT_OUT)/$(PROJECT).sym projectinfo

# create the output directories
dirs:
@-if [ ! -e $(PROJECT_OUT) ]; then mkdir $(PROJECT_OUT); fi;
@-$(foreach DIR,$(DIRS), if [ ! -e $(PROJECT_OUT)/$(DIR) ]; \
 then mkdir -p $(PROJECT_OUT)/$(DIR); fi; )

我对整个品牌和制作主题都非常陌生,因此我很难弄清楚问题。感谢一切帮助。

I have a problem with a makefile that's part of a repository. I already posted this question but don't know how to add some code lines after, so I'm trying it here.There is a problem with the makefile that has the common make rules. When I run make, I get the following error: C:\Mios32/include/makefile/common.mk:143: *** multiple target patterns. Stop.

Here's the code from common.mk file from line 142 to 144:

# rule to create .elf file                                 
$(PROJECT_OUT)/$(PROJECT).elf: $(ALL_OBJS)
    @$(CC) $(CFLAGS) $(ALL_OBJS) $(LIBS) $(LDFLAGS) -o$@

I'm guessing it's a problem with all_objs, cause these lines right before seem to work:

# rule to create a .hex and .bin file                                               
%.bin : $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJCOPY) 
lt; -O binary $@
%.hex : $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJCOPY) 
lt; -O ihex $@

# rule to create a listing file from .elf                                          
%.lss: $(PROJECT_OUT)/$(PROJECT).elf
    @$(OBJDUMP) -w -h -S -C 
lt; > $@

# rule to create a symbol table from .elf                                          
%.sym: $(PROJECT_OUT)/$(PROJECT).elf
    @$(NM) -n 
lt; > $@

Here's some additional lines with all_objs:

# list of all objects                                                            
ALL_OBJS = $(addprefix $(PROJECT_OUT)/, $(THUMB_OBJS) $(THUMB_CPP_OBJS) $(THUMB_AS_OBJS) 
$(ARM_OBJS) $(ARM_CPP_OBJS) $(ARM_AS_OBJS))

# list of all dependency files                                                 
ALL_DFILES = $(ALL_OBJS:.o=.d)

And here's some additional lines with Project_out and project:

# where should the output files be located                                    
PROJECT_OUT ?= $(PROJECT)_build

# default linker flags                                                            
LDFLAGS += -T $(LD_FILE) -mthumb -u _start -Wl,--gc-section  -Xlinker -M -Xlinker - 
Map=$(PROJECT_OUT)/$(PROJECT).map  -nostartfiles -lstdc++

# default rule                                                                       
all: dirs cleanhex $(PROJECT).hex $(PROJECT_OUT)/$(PROJECT).bin 
$(PROJECT_OUT)/$(PROJECT).lss $(PROJECT_OUT)/$(PROJECT).sym projectinfo

# create the output directories
dirs:
@-if [ ! -e $(PROJECT_OUT) ]; then mkdir $(PROJECT_OUT); fi;
@-$(foreach DIR,$(DIRS), if [ ! -e $(PROJECT_OUT)/$(DIR) ]; \
 then mkdir -p $(PROJECT_OUT)/$(DIR); fi; )

I'm pretty new to the whole Make and Makefile topic, so I'm having a hard time figuring out the problem. I appreciate every help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归途 2025-02-10 07:33:51

您应该在问题中清楚您正在处理什么操作系统。从您在Windows上工作的错误消息似乎是从Windows上工作的。您要使用的MakeFile是非常针对GNU/Linux或MacOS等UNIX系统的非常针对的。

如果您不熟悉Windows和Unix之间的差异(它们是巨大而深的),那么您肯定会在开始工作之前要做很多学习。

要使用Windows上的Unix环境,您需要使用WSL或Cygwin之类的东西,或者至少安装Mingw Shell环境。当您这样做时,您需要使用Unix路径,而不是Windows路径。 Windows路径使用backSlashes(是UNIX中的逃脱序列)和驱动器字母(在Unix中没有等效的序列),尤其是:字符特殊可用于使使用驱动器字母的路径是一个特殊的问题。

您可以通过添加$(info ...)函数来调试makefile,以向您显示变量的值:

# rule to create .elf file
$(info PROJECT_OUT = $(PROJECT_OUT))
$(info PROJECT = $(PROJECT))
$(info ALL_OBJS = $(ALL_OBJS))                                
$(PROJECT_OUT)/$(PROJECT).elf: $(ALL_OBJS)
        @$(CC) $(CFLAGS) $(ALL_OBJS) $(LIBS) $(LDFLAGS) -o$@

You should be clear in your question what OS you're working on. It seems from the error message above you're working on Windows. The makefile you're trying to use is very clearly targeted at a UNIX system like GNU/Linux or possibly MacOS.

If you are not familiar with the differences between Windows and UNIX (which are vast and deep) you will definitely have a lot of learning to do before you can even start to get this working.

To use UNIX environments on Windows you need to use something like WSL, or Cygwin, or at least install a MinGW shell environment. When you do that you need to be using UNIX paths, not Windows paths. Windows paths use backslashes (which are escape sequences in UNIX) and drive letters (which have no equivalent in UNIX) and in makefiles in particular the : character is special to make so using paths with drive letters is a problem.

You can debug your makefile by adding $(info ...) functions to show you the value of variables:

# rule to create .elf file
$(info PROJECT_OUT = $(PROJECT_OUT))
$(info PROJECT = $(PROJECT))
$(info ALL_OBJS = $(ALL_OBJS))                                
$(PROJECT_OUT)/$(PROJECT).elf: $(ALL_OBJS)
        @$(CC) $(CFLAGS) $(ALL_OBJS) $(LIBS) $(LDFLAGS) -o$@
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文