我的makefile是:
LIB= -lSDL2
OBJ= Color.o Emitter.o main.o Matrix2.o Particle.o ParticleSystem.o \
Vector2.o Vector3.o
# link, load and compile object files
all: $(OBJ)
g++ -o output *.o ${LIB}
# generate object files
Color.o: Color.cpp Color.h
g++ -c Color.cpp
Emitter.o: Emitter.cpp Emitter.h
g++ -c Emitter.cpp
main.o: main.cpp
g++ -c main.cpp
Matrix2.o: Matrix2.cpp Matrix2.h
g++ -c Matrix2.cpp
Particle.o: Particle.cpp Particle.h
g++ -c Particle.cpp
ParticleSystem.o: ParticleSystem.cpp ParticleSystem.h
g++ -c ParticleSystem.cpp
Vector2.o: Vector2.cpp Vector2.h
g++ -c Vector2.cpp
Vector3.o: Vector3.cpp Vector3.h
g++ -c Vector3.cpp
# clean up
.PHONY: clean
clean:
rm *.o
错误是:
g++ -c Color.cpp
g++ -c Emitter.cpp
g++ -c main.cpp
g++ -c Matrix2.cpp
g++ -c Particle.cpp
g++ -c ParticleSystem.cpp
g++ -c Vector2.cpp
g++ -c Vector3.cpp
g++ -o output *.o -lSDL2
Particle.o: In function `Particle::Particle()':
Particle.cpp:(.text+0x24): undefined reference to `Vector2::Vector2()'
Particle.cpp:(.text+0x34): undefined reference to `Vector2::Vector2()'
Particle.cpp:(.text+0x44): undefined reference to `Vector2::Vector2()'
Particle.cpp:(.text+0x54): undefined reference to `Color::Color()'
Particle.cpp:(.text+0x64): undefined reference to `Color::Color()'
Particle.cpp:(.text+0x74): undefined reference to `Color::Color()'
main.o: In function `main':
main.cpp:(.text+0x17): undefined reference to `usage()'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
我不明白为什么编译器会报告未定义的引用错误,因为我编译了正确的程序(根据我的说法!)。 我应该在makefile中更改什么才能删除此错误?请帮忙。