c - "No rule to make target" althoug the rule exists -


i have issue makefile says no rule make target /obj/%.o, needed /bin/exec. stop. understand have it:

# define c compiler use cc = gcc  # define compile-time flags # add -ddebug debug mode cflags = -wall   # define directories containing header files includes = -i/includes  # define src folder src_folder = /src  # define src files src = $(wildcard $(src_folder)/%.cpp)  # define object folder obj_folder = /obj  # define obj files obj = $(patsubst %.cpp, %.o, $(src))  # define binary path bin_folfer = /bin  # define executable file  main = $(bin_folfer)/exec  # compile object files $(obj_folder)/%.o: $(src_folder)/%.cpp     $(cc) $(cflags) $< -o $@  # build $(main): $(obj_folder)/%.o     $(cc) $(cflags) $^ -o $@  # cleaning  .phony: clean  clean:     rm -f $(obj_folder)/%.o  

i sorry possible major errors in makefile, first makefile. doing wrong?

$(main): $(obj_folder)/%.o 

requests %.o exactly. % not act pattern here, because not appear on both sides of rule. need use $(obj) variable there. first need fixed, because replacing extension, need replace directory too.

  1. finish $(obj) variable (as lutin said) (ok, modified bit; presume want direct descendants of directory):

    src = $(wildcard $(src_folder)/*.cpp) obj = $(patsubst $(src_folder)/%.cpp, $(obj_folder)/%.o, $(src)) 
  2. fix rule use $(obj) variable:

    $(main): $(obj) 
  3. oh, , don't want src_folder, obj_folder , bin_folder start / puts them in filesystem root it's not project lives. , patterns above should not end slash either.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -