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

时间:2013-04-26 05:20:44

标签: c++ makefile

我有这个目录结构:

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

这是我makefile内部的src

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

1 个答案:

答案 0 :(得分:2)

在您的规则$(CC) $(CFLAGS) $(EXTERNOBJ) -c $@ $(TARGETS)中,您应该将-c更改为-o,否则g++会认为$@是输入文件并查找{{1} },但尚不存在。