2

I've a problem compiling my C++ project using a makefile. The structure of the project is like:

  • gui/:
    • Basicshape.cpp / .h
    • Functionable.cpp / .h
  • logic/:
    • Matrix.cpp/ .h
    • Cell.cpp/ .h
    • Item.cpp / .h
    • Position.cpp / .h
  • main.cpp
  • makefile

Here's the content of the makefile:

FLAGS=--std='c++20' -Wall -Wextra -Wpedantic -lfltk

all:CandyCrush

CandyCrush: main.o Matrice.o Cell.o Item.o Position.o BasicShape.o Functionable.o
    g++ main.o Matrice.o Cell.o Item.o Position.o BasicShape.o Functionable.o -o CandyCrush

Cell.o: logic/Cell.h logic/Cell.cpp
    g++ $(FLAGS) -c logic/Cell.cpp -o Cell.o
Item.o: logic/Item.h logic/Item.cpp
    g++ $(FLAGS) -c logic/Item.cpp -o Item.o
Position.o: logic/Position.h logic/Position.cpp
    g++ $(FLAGS) -c logic/Position.cpp -o Position.o
Matrice.o: logic/Matrice.h logic/Matrice.cpp
    g++ $(FLAGS) -c logic/Matrice.cpp -o Matrice.o

BasicShape.o: gui/BasicShapes.h gui/BasicShapes.cpp
    g++ $(FLAGS) -c gui/BasicShapes.cpp -o BasicShape.o
Functionable.o: gui/Functionable.h gui/Functionable.cpp
    g++ $(FLAGS) -c gui/Functionable.cpp -o Functionable.o

main.o: main.cpp
    g++ $(FLAGS) -c main.cpp -o main.o

clear:
    rm *.o

I know it can be shortened but for debugging purposes and the fact than I'm still learning I prefer keeping this structure.

By typing make in my terminal, I've this error and I'm not sure why :

/usr/bin/ld: BasicShape.o: warning: relocation against `_ZTV9Rectangle' in read-only section `.text'
/usr/bin/ld: BasicShape.o: in function `Rectangle::Rectangle(Point, int, int, unsigned int, unsigned int)':
BasicShapes.cpp:(.text+0xdd): undefined reference to `vtable for Rectangle'
/usr/bin/ld: BasicShapes.cpp:(.text+0xf3): undefined reference to `vtable for Rectangle'
/usr/bin/ld: BasicShape.o: in function `Circle::Circle(Point, int, unsigned int, unsigned int)':
BasicShapes.cpp:(.text+0x225): undefined reference to `vtable for Circle'
/usr/bin/ld: BasicShapes.cpp:(.text+0x23b): undefined reference to `vtable for Circle'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [makefile:6: CandyCrush] Error 1
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220

0 Answers0