代码之家  ›  专栏  ›  技术社区  ›  Taylor

makefile错误:打开依赖文件.d/file_姓名.Td:没有这样的文件或目录

  •  0
  • Taylor  · 技术社区  · 6 年前

    我正在尝试修改一个生成文件( that I found here )自动生成依赖项。但是,当我跑的时候 make

    t@t-XPS-13-9365:~/pf/test$ make
    g++ -MT .o/test_resamplers.o -MD -MP -MF .d/test_resamplers.Td -std=c++11 -g -Wall -Wextra -pedantic -I/usr/local/include/UnitTest++ -I/usr/include/eigen3 -I../include -c -o .o/test_resamplers.o test_resamplers.cpp
    test_resamplers.cpp:155:1: fatal error: opening dependency file .d/test_resamplers.Td: No such file or directory
     }
     ^
    compilation terminated.
    Makefile:66: recipe for target '.o/test_resamplers.o' failed
    make: *** [.o/test_resamplers.o] Error 1
    

    也许我用错了 DEPFLAGS 我的makefile中的变量。我确实把编译器从 clang++ g++

    # output binary
    BIN := run_tests
    
    # source files
    SRCS := \
        main.cpp test_cf_filters.cpp test_resamplers.cpp test_rv_eval.cpp \
        test_rv_samp.cpp test_utils.cpp
    
    # intermediate directory for generated object files
    OBJDIR := .o
    # intermediate directory for generated dependency files
    DEPDIR := .d
    
    # object files, auto generated from source files
    OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))
    
    # compilers (at least gcc and clang) don't create the subdirectories automatically
    $(shell mkdir -p $(dir $(OBJS)) >/dev/null)
    
    # C++ compiler
    CXX := g++
    # linker
    LD := g++
    
    # C++ flags
    CXXFLAGS := -std=c++11
    # C/C++ flags
    CPPFLAGS := -g -Wall -Wextra -pedantic -I/usr/local/include/UnitTest++ -I/usr/include/eigen3 -I../include
    # linker flags
    LDFLAGS := "-L../bin" "-L/usr/local/lib"
    # flags required for dependency generation; passed to compilers
    DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td
    # libraries
    LDLIBS := -lpf -lUnitTest++
    
    # compile C++ source files
    COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -o $@
    # link object files to binary
    LINK.o = $(LD) $(LDFLAGS) $(LDLIBS) -o $@
    # precompile step
    PRECOMPILE =
    # postcompile step
    POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
    
    all: $(BIN)
    
    .PHONY: clean
    clean:
        $(RM) -r $(OBJDIR) $(DEPDIR)
    
    .PHONY: help
    help:
        @echo available targets: all dist clean distclean install uninstall check
    
    $(BIN): $(OBJS)
        $(LINK.o) $^
    
    $(OBJDIR)/%.o: %.c
    $(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
        $(PRECOMPILE)
        $(COMPILE.c) $<
        $(POSTCOMPILE)
    
    $(OBJDIR)/%.o: %.cpp
    $(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d
        $(PRECOMPILE)
        $(COMPILE.cc) $<
        $(POSTCOMPILE)
    
    $(OBJDIR)/%.o: %.cc
    $(OBJDIR)/%.o: %.cc $(DEPDIR)/%.d
        $(PRECOMPILE)
        $(COMPILE.cc) $<
        $(POSTCOMPILE)
    
    $(OBJDIR)/%.o: %.cxx
    $(OBJDIR)/%.o: %.cxx $(DEPDIR)/%.d
        $(PRECOMPILE)
        $(COMPILE.cc) $<
        $(POSTCOMPILE)
    
    .PRECIOUS = $(DEPDIR)/%.d
    $(DEPDIR)/%.d: ;
    
    -include $(DEPS)
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   MadScientist    6 年前

    使用以下行创建对象目录:

    $(shell mkdir -p $(dir $(OBJS)) >/dev/null)
    

    但你不能创造 DEPDIR 因此,当编译器尝试在那里创建文件时,它会失败。

    $(shell mkdir -p $(DEPDIR))
    

    或者,将其添加到上一个shell函数中。