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 to protector :: Winner :: Winner () 'main.cpp :(. Text + 0xa5): unqualified reference to protector::Winner::addWinner(protector::Player const&)' main.cpp:(.text+0xb1): undefined reference to protector :: Generator :: Generator () 'main.cpp :(. Text + 0xbd): undefined reference to protector::Generator::~Generator()' main.cpp:(.text+0xc9): undefined reference to protector: : Winner :: ~ Winner () 'main.cpp :(. Text + 0x124): undefined reference to protector::Winner::~Winner()' Way.o: In function protector :: 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.

Closed due to the fact that it is off topic by participants aleksandr barakin , Alex , user194374, fori1ton , Denis Bubnov Nov 29 '16 at 13:55 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, Alex, Community Spirit, fori1ton, Denis Bubnov
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    Well, he writes: undefined reference to ... Look for where these methods are described by you, and whether they are turned off by any preprocessor directives. - PinkTux

1 answer 1

Stupid mistake. Did not include some classes in the makefile. The topic can be considered closed.

  • if the error is stupid, and the question is not useful to other participants, then maybe you should delete the question? or mark your answer as a solution (the green daw below the digit to the left of the answer). - Alex
  • @Alex You are right, thanks :) - pierdere