I am writing a program that worked fine in Dev C ++ and Visual Studio, and flew on the linux terminal with the indicated errors on compilation. I compile via makefile:
### settings CC = g++ FLAGS = -Wall OBJ = Maze.o Way.o Player.o HEADERS = Maze.h Way.h Player.h ### run the main executable run : main.exe ### run the unit tests test : Test.exe ### clean build from source rebuild : clean build ### build executables build : main.exe Test.exe ### set debug flag, rebuild and run unit tests debug : FLAGS += -DDEBUG debug : clean Test.exe ### executables main.exe : main.cpp ${OBJ} ${HEADERS} $(CC) $(FLAGS) main.cpp $(OBJ) -o main.exe test.exe : test.cpp $(OBJ) $(HEADERS) $(CC) $(FLAGS) Test.cpp $(OBJ) -o Test.exe ### object files for the classes Player.o : Player.cpp $(CC) $(FLAGS) -c Player.cpp -o Player.o Maze.o : Maze.cpp $(CC) $(FLAGS) -c Maze.cpp -o Maze.o Way.o : Way.cpp $(CC) $(FLAGS) -c Way.cpp -o Way.o ### clean all executables and object files clean : rm -f *.exe *.o PS In my program 2 maina (normal and for the Test class), in Deve I just comment on the second. But errors pop up for the main maina (not a test one).
g ++ -Wall main.cpp Maze.o Way.o Player.o -o main.exe /tmp/ccalG046.o: In function
main': main.cpp:(.text+0x92): undefined reference toprotector :: Winner :: Winner () 'main.cpp :(. Text + 0xa5): unqualified reference toprotector::Winner::addWinner(protector::Player const&)' main.cpp:(.text+0xb1): undefined reference toprotector :: Generator :: Generator () 'main.cpp :(. Text + 0xbd): undefined reference toprotector::Generator::~Generator()' main.cpp:(.text+0xc9): undefined reference toprotector: : Winner :: ~ Winner () 'main.cpp :(. Text + 0x124): undefined reference toprotector::Winner::~Winner()' Way.o: In functionprotector :: Way :: wasInjured (protector: : Player *, protector :: Monster) ': Way.cpp :(. Text + 0x5df): undefined reference to protector :: Monster :: getLethalArea ()' collect2: error: ld returned 1 exit status makefile: 25: recipe for target 'main.exe' failed make: *** [main.exe] Error 1
If the makefile has nothing to do with it, please tell me what exactly the compiler may not like in constructors, destructors and similar arguments? I will correct the code.
undefined reference to ...Look for where these methods are described by you, and whether they are turned off by any preprocessor directives. - PinkTux