【问题标题】:Nothing to be done and No rule to make target无事可做,没有制定目标的规则
【发布时间】:2022-01-16 01:59:42
【问题描述】:

我正在尝试制作子程序的目标文件。我遵循以下(https://unix.stackexchange.com/questions/585452/makefile-error-no-rule-to-make-target-how-to-solve-ithttps://cs50.stackexchange.com/questions/10847/error-make-no-rule-to-make-target-mario-stop/10852)但无法修复错误。使用的make文件是:

ifndef PVFMM_DIR
PVFMM_DIR=./..
endif

-include $(PVFMM_DIR)/MakeVariables

ifndef CXX_PVFMM
$(error Cannot find file: MakeVariables)
endif

FC_PVMM = mpif90
FC = mpif90

FC=$(FC_PVFMM) # TODO: for now, FC must be provided by user
CC=$(CC_PVFMM) # TODO: for now, CC must be provided by user
CXX=$(CXX_PVFMM)
CXXFLAGS=$(CXXFLAGS_PVFMM)
LDLIBS=$(LDLIBS_PVFMM)

RM = rm -f
MKDIRS = mkdir -p

BINDIR = ./bin
SRCDIR = ./src
OBJDIR = ./obj
INCDIR = ./include

TARGET_BIN = \
       $(OBJDIR)/example-f.o

all : example-f.o

example-f.o: $(SRCDIR)/%.f90
    -@$(MKDIRS) $(dir $@)
    @echo "here" $(dir $@)
    $(PVFMM_DIR)/libtool --mode=link --tag=FC mpif90 $(CXXFLAGS) -I$(INCDIR) $^ $(LDLIBS) -c $@

我收到以下错误:

cd ./examples && make;
make[1]: Entering directory '/home/bidesh/Coding/FMM/pvfmm-develop/examples'
make[1]: *** No rule to make target 'src/%.f90', needed by 'example-f.o'. Stop.
make[1]: Leaving directory '/home/bidesh/Coding/FMM/pvfmm-develop/examples'
Makefile:1410: recipe for target 'all-examples' failed
make: *** [all-examples] Error 2

谁能告诉我我犯的错误?

我现在已将 make 文件更改为:

TARGET_BIN = \
       $(OBJDIR)/example-f.o

all : $(TARGET_BIN)

$(OBJDIR)/%: $(SRCDIR)/%.f90
    -@$(MKDIRS) $(dir $@)
    @echo "here" $(dir $@)
    $(PVFMM_DIR)/libtool --mode=link --tag=FC mpif90 $(CXXFLAGS) -I$(INCDIR) $^ $(LDLIBS) -c $@

并且example-f.f90子程序存在于src中。当我尝试编译时,我收到以下错误:

make[1]: Entering directory '/home/bidesh/Coding/FMM/pvfmm-develop/examples'
make[1]: *** No rule to make target 'obj/example-f.o', needed by 'all'. Stop.
make[1]: Leaving directory '/home/bidesh/Coding/FMM/pvfmm-develop/examples'
Makefile:1410: recipe for target 'all-examples' failed
make: *** [all-examples] Error 2

也许我犯了一些愚蠢的错误。我是 Makefile 和 Linux 环境的新手。我将被帮助了解错误。谢谢。

【问题讨论】:

    标签: makefile compilation


    【解决方案1】:

    您收到此错误是因为:

    example-f.o: $(SRCDIR)/%.f90
    

    不是模式规则。模式规则的 目标 中必须有模式 (%)。先决条件中的模式是可选的,而目标中的模式是强制性的。

    这只是构建目标 example-f.o 的显式规则,它将文字文件 src/%.f90 列为先决条件,并且该文件不存在并且 make 不知道如何构建它,这就是它告诉你。

    【讨论】:

    • 非常感谢您的回复。我将其更改为: TARGET_BIN = \ $(OBJDIR)/example-fo all : $(TARGET_BIN) $(OBJDIR)/%: $(SRCDIR)/%.f90 -@$(MKDIRS) $(dir $@) @ echo "这里" $(dir $@) $(PVFMM_DIR)/libtool --mode=link --tag=FC mpif90 $(CXXFLAGS) -I$(INCDIR) $^ $(LDLIBS) -c $@
    • 仍然给出: make[1]: Entering directory '/home/bidesh/Coding/FMM/pvfmm-develop/examples' make[1]: *** No rule to make target ' obj/example-f.o','all' 需要。停止。 make[1]: 离开目录'/home/bidesh/Coding/FMM/pvfmm-develop/examples' Makefile:1410: 目标'all-examples'的配方失败 make: *** [all-examples] Error 2跨度>
    • 虽然子程序存在于example/src中。
    • 不可能是你描述的那样。我建议调用 make -d 来获取 make 以打印有关正在发生的事情的调试输出。请确保父makefile 使用变量$(MAKE) 来调用子make,而不是文字命令make。输出会很长,因此您可能希望将其重定向到一个文件,然后搜索它要在哪里构建目标 obj/example-f.o 并查看它为什么会确定此模式规则不匹配。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2011-09-08
    • 1970-01-01
    相关资源
    最近更新 更多