Reputation: 95
I am trying to make an object file of a subroutine. I have followed the following (https://unix.stackexchange.com/questions/585452/makefile-error-no-rule-to-make-target-how-to-solve-it, https://cs50.stackexchange.com/questions/10847/error-make-no-rule-to-make-target-mario-stop/10852) but couldn't fix the error. The make file that is used is:
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 $@
I get the following error:
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
Can anyone let me know the mistake I am making?
I have now changed the make file as:
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 $@
And the example-f.f90 subroutine exists in src. When I tried to compile, I received the following error:
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
Maybe I am making some silly mistake. I am new to the Makefile and Linux environment. I will be helped to known the error. Thank you.
Upvotes: 1
Views: 186
Reputation: 100856
You get this error because this:
example-f.o: $(SRCDIR)/%.f90
is not a pattern rule. A pattern rule must have a pattern (%
) in the target. The pattern in the prerequisite is optional, but the pattern in the target is mandatory.
That is just an explicit rule for building the target example-f.o
which lists the literal file src/%.f90
as a prerequisite, and that file doesn't exist and make doesn't know how to build it, which is what it tells you.
Upvotes: 2