0

My makefile is :

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

The error is :

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

I dont understand why undefined reference error is being reported by the compiler as I have compiled the program right (according to me!). What should I change in the makefile to remove this error? Please help.

demonSlayer
  • 185
  • 5
  • 14

0 Answers0