Makefile:没有这样的文件或目录

Makefile: No such file or directory

本文关键字:文件 Makefile      更新时间:2023-10-16

目录结构如下:

 - src
  - /GUILayer
  - /PhysicLayer
  - /LogicLayer
  - /Utilities
  - main.cpp
  - makefile
  - makefile.inc

这是src中当前的makefile

include makefile.inc
DIRS    = PhysicLayer LogicLayer GUILayer Utilities
OBJLIBS = PhysicLayer.a LogicLayer.a GUILayer.a Utilities.a
EXTERNOBJ =  $(foreach path, $(DIRS), $(wildcard $(path)/*.o))
TARGETS = main.cpp 
EXE = main
all : $(EXE)
%.a :
    -for d in $(DIRS); do (cd $$d; $(MAKE)); done
    ar cr $@ $^
main: $(OBJLIBS)
    $(ECHO) $(CC) $(CFLAGS) $(EXTERNOBJ) $(OBJLIBS)  -o $@ $(TARGETS)
    $(CC) $(CFLAGS) $(EXTERNOBJ) $(OBJLIBS)  -o $@ $(TARGETS) 
clean :
    -$(RM) -f ./main
    find . -name "*.o" -type f -print | xargs /bin/rm -f
    find . -name "*.a" -type f -print | xargs /bin/rm -f

文件夹内的文件生成。o很好,但main根本不生成。下面是终端的输出:

g++ -Wall -pedantic -pedantic-errors -g -ggdb PhysicLayer.a LogicLayer.a GUILayer.a Utilities.a -o main main.cpp
/tmp/ccA3VJed.o: In function `main':
/home/user/Desktop/project/src/main.cpp:14: undefined reference to `Indexador::Indexador()'
/home/user/Desktop/project/src/main.cpp:19: undefined reference to `Indexador::indexar(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/user/Desktop/project/src/main.cpp:38: undefined reference to `Indexador::~Indexador()'
/home/user/Desktop/project/src/main.cpp:38: undefined reference to `Indexador::~Indexador()'
collect2: ld returned 1 exit status
make: *** [main] Error 1

在您的规则$(CC) $(CFLAGS) $(EXTERNOBJ) -c $@ $(TARGETS)中,您应该将-c更改为-o,否则g++将假设$@是一个输入文件并查找尚未存在的main