Makefile error no rule found but rule is present












1















This Makefile



CC = gcc

INC_PATH = -I../common/

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR :=./obj
OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

COMMONDIR := ../common
SOURCESCOMMON := $(wildcard $(COMMONDIR)/*.c)
OBJDIRCOMMON := $(COMMONDIR)/obj
OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON))
DEPENDSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.d, $(SOURCESCOMMON))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# OBJS_LOC is in current working directory,
EXECUTABLE := ../server
# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: $(EXECUTABLE)

clean:
$(RM) $(OBJECTS) $(DEPENDS) $(EXECUTABLE)

# Linking the executable from the object files
# $^ # "src.c src.h" (all prerequisites)
$(EXECUTABLE): $(OBJECTSCOMMON) $(OBJECTS)
$(CC) $(WARNING) $^ -o $@

-include $(DEPENDS) $(DEPENDSCOMMON)

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@

$(OBJDIRCOMMON):
mkdir -p $(OBJDIRCOMMON)

$(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
$(CC) $(WARNING) -MMD -MP -c $< -o $@


is generating the error:



 make[1]: *** No rule to make target '../common/obj/utilities.o', needed by '../server'.  Stop.


The main rule generating the rule has as input $(OBJECTSCOMMON) referring to the objects file *.o contained in the directory OBJDIRCOMMON. The rule to generate this objects has not explicit target but it is:



$(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
$(CC) $(WARNING) -MMD -MP -c $< -o $@


and I think this is generating the error. I was expecting the definition OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON)) made the rule and valid to generate $()



However a similar rule is used to generate $(OBJECTS) in the same Makefile and it is workin:



$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@


So why the different behaviour between the rules?










share|improve this question



























    1















    This Makefile



    CC = gcc

    INC_PATH = -I../common/

    SOURCEDIR := ./
    SOURCES := $(wildcard $(SOURCEDIR)/*.c)
    OBJDIR :=./obj
    OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
    DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

    COMMONDIR := ../common
    SOURCESCOMMON := $(wildcard $(COMMONDIR)/*.c)
    OBJDIRCOMMON := $(COMMONDIR)/obj
    OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON))
    DEPENDSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.d, $(SOURCESCOMMON))

    # ADD MORE WARNINGS!
    WARNING := -Wall -Wextra

    # OBJS_LOC is in current working directory,
    EXECUTABLE := ../server
    # .PHONY means these rules get executed even if
    # files of those names exist.
    .PHONY: all clean

    # The first rule is the default, ie. "make",
    # "make all" and "make parking" mean the same
    all: $(EXECUTABLE)

    clean:
    $(RM) $(OBJECTS) $(DEPENDS) $(EXECUTABLE)

    # Linking the executable from the object files
    # $^ # "src.c src.h" (all prerequisites)
    $(EXECUTABLE): $(OBJECTSCOMMON) $(OBJECTS)
    $(CC) $(WARNING) $^ -o $@

    -include $(DEPENDS) $(DEPENDSCOMMON)

    $(OBJDIR):
    mkdir -p $(OBJDIR)

    $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
    $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@

    $(OBJDIRCOMMON):
    mkdir -p $(OBJDIRCOMMON)

    $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
    $(CC) $(WARNING) -MMD -MP -c $< -o $@


    is generating the error:



     make[1]: *** No rule to make target '../common/obj/utilities.o', needed by '../server'.  Stop.


    The main rule generating the rule has as input $(OBJECTSCOMMON) referring to the objects file *.o contained in the directory OBJDIRCOMMON. The rule to generate this objects has not explicit target but it is:



    $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
    $(CC) $(WARNING) -MMD -MP -c $< -o $@


    and I think this is generating the error. I was expecting the definition OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON)) made the rule and valid to generate $()



    However a similar rule is used to generate $(OBJECTS) in the same Makefile and it is workin:



    $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
    $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@


    So why the different behaviour between the rules?










    share|improve this question

























      1












      1








      1








      This Makefile



      CC = gcc

      INC_PATH = -I../common/

      SOURCEDIR := ./
      SOURCES := $(wildcard $(SOURCEDIR)/*.c)
      OBJDIR :=./obj
      OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
      DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

      COMMONDIR := ../common
      SOURCESCOMMON := $(wildcard $(COMMONDIR)/*.c)
      OBJDIRCOMMON := $(COMMONDIR)/obj
      OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON))
      DEPENDSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.d, $(SOURCESCOMMON))

      # ADD MORE WARNINGS!
      WARNING := -Wall -Wextra

      # OBJS_LOC is in current working directory,
      EXECUTABLE := ../server
      # .PHONY means these rules get executed even if
      # files of those names exist.
      .PHONY: all clean

      # The first rule is the default, ie. "make",
      # "make all" and "make parking" mean the same
      all: $(EXECUTABLE)

      clean:
      $(RM) $(OBJECTS) $(DEPENDS) $(EXECUTABLE)

      # Linking the executable from the object files
      # $^ # "src.c src.h" (all prerequisites)
      $(EXECUTABLE): $(OBJECTSCOMMON) $(OBJECTS)
      $(CC) $(WARNING) $^ -o $@

      -include $(DEPENDS) $(DEPENDSCOMMON)

      $(OBJDIR):
      mkdir -p $(OBJDIR)

      $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
      $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@

      $(OBJDIRCOMMON):
      mkdir -p $(OBJDIRCOMMON)

      $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
      $(CC) $(WARNING) -MMD -MP -c $< -o $@


      is generating the error:



       make[1]: *** No rule to make target '../common/obj/utilities.o', needed by '../server'.  Stop.


      The main rule generating the rule has as input $(OBJECTSCOMMON) referring to the objects file *.o contained in the directory OBJDIRCOMMON. The rule to generate this objects has not explicit target but it is:



      $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
      $(CC) $(WARNING) -MMD -MP -c $< -o $@


      and I think this is generating the error. I was expecting the definition OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON)) made the rule and valid to generate $()



      However a similar rule is used to generate $(OBJECTS) in the same Makefile and it is workin:



      $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
      $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@


      So why the different behaviour between the rules?










      share|improve this question














      This Makefile



      CC = gcc

      INC_PATH = -I../common/

      SOURCEDIR := ./
      SOURCES := $(wildcard $(SOURCEDIR)/*.c)
      OBJDIR :=./obj
      OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
      DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

      COMMONDIR := ../common
      SOURCESCOMMON := $(wildcard $(COMMONDIR)/*.c)
      OBJDIRCOMMON := $(COMMONDIR)/obj
      OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON))
      DEPENDSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.d, $(SOURCESCOMMON))

      # ADD MORE WARNINGS!
      WARNING := -Wall -Wextra

      # OBJS_LOC is in current working directory,
      EXECUTABLE := ../server
      # .PHONY means these rules get executed even if
      # files of those names exist.
      .PHONY: all clean

      # The first rule is the default, ie. "make",
      # "make all" and "make parking" mean the same
      all: $(EXECUTABLE)

      clean:
      $(RM) $(OBJECTS) $(DEPENDS) $(EXECUTABLE)

      # Linking the executable from the object files
      # $^ # "src.c src.h" (all prerequisites)
      $(EXECUTABLE): $(OBJECTSCOMMON) $(OBJECTS)
      $(CC) $(WARNING) $^ -o $@

      -include $(DEPENDS) $(DEPENDSCOMMON)

      $(OBJDIR):
      mkdir -p $(OBJDIR)

      $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
      $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@

      $(OBJDIRCOMMON):
      mkdir -p $(OBJDIRCOMMON)

      $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
      $(CC) $(WARNING) -MMD -MP -c $< -o $@


      is generating the error:



       make[1]: *** No rule to make target '../common/obj/utilities.o', needed by '../server'.  Stop.


      The main rule generating the rule has as input $(OBJECTSCOMMON) referring to the objects file *.o contained in the directory OBJDIRCOMMON. The rule to generate this objects has not explicit target but it is:



      $(OBJDIRCOMMON)/%.o: $(SOURCESCOMMON)/%.c | $(OBJDIRCOMMON)
      $(CC) $(WARNING) -MMD -MP -c $< -o $@


      and I think this is generating the error. I was expecting the definition OBJECTSCOMMON := $(patsubst $(COMMONDIR)/%.c,$(OBJDIRCOMMON)/%.o, $(SOURCESCOMMON)) made the rule and valid to generate $()



      However a similar rule is used to generate $(OBJECTS) in the same Makefile and it is workin:



      $(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
      $(CC) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@


      So why the different behaviour between the rules?







      makefile compilation object-files






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 20:30









      Francesco BoiFrancesco Boi

      2,74522643




      2,74522643
























          1 Answer
          1






          active

          oldest

          votes


















          2














          $(SOURCESCOMMON)/%.c expands to $(wildcard $(COMMONDIR)/*.c)/%.c, so the pattern will contain something like ../common/utilities.c/%.c (possibly with a different file name). This file does not exist, so the pattern rule is ignored.



          The other rule uses $(SOURCEDIR), so it does not have this issue.






          share|improve this answer


























          • Thanks...it worked. I should have looked carefully :)

            – Francesco Boi
            Jan 2 at 20:38












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012763%2fmakefile-error-no-rule-found-but-rule-is-present%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          $(SOURCESCOMMON)/%.c expands to $(wildcard $(COMMONDIR)/*.c)/%.c, so the pattern will contain something like ../common/utilities.c/%.c (possibly with a different file name). This file does not exist, so the pattern rule is ignored.



          The other rule uses $(SOURCEDIR), so it does not have this issue.






          share|improve this answer


























          • Thanks...it worked. I should have looked carefully :)

            – Francesco Boi
            Jan 2 at 20:38
















          2














          $(SOURCESCOMMON)/%.c expands to $(wildcard $(COMMONDIR)/*.c)/%.c, so the pattern will contain something like ../common/utilities.c/%.c (possibly with a different file name). This file does not exist, so the pattern rule is ignored.



          The other rule uses $(SOURCEDIR), so it does not have this issue.






          share|improve this answer


























          • Thanks...it worked. I should have looked carefully :)

            – Francesco Boi
            Jan 2 at 20:38














          2












          2








          2







          $(SOURCESCOMMON)/%.c expands to $(wildcard $(COMMONDIR)/*.c)/%.c, so the pattern will contain something like ../common/utilities.c/%.c (possibly with a different file name). This file does not exist, so the pattern rule is ignored.



          The other rule uses $(SOURCEDIR), so it does not have this issue.






          share|improve this answer















          $(SOURCESCOMMON)/%.c expands to $(wildcard $(COMMONDIR)/*.c)/%.c, so the pattern will contain something like ../common/utilities.c/%.c (possibly with a different file name). This file does not exist, so the pattern rule is ignored.



          The other rule uses $(SOURCEDIR), so it does not have this issue.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 20:39

























          answered Jan 2 at 20:34









          Florian WeimerFlorian Weimer

          18.3k31148




          18.3k31148













          • Thanks...it worked. I should have looked carefully :)

            – Francesco Boi
            Jan 2 at 20:38



















          • Thanks...it worked. I should have looked carefully :)

            – Francesco Boi
            Jan 2 at 20:38

















          Thanks...it worked. I should have looked carefully :)

          – Francesco Boi
          Jan 2 at 20:38





          Thanks...it worked. I should have looked carefully :)

          – Francesco Boi
          Jan 2 at 20:38




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012763%2fmakefile-error-no-rule-found-but-rule-is-present%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]