When I compile a set of programs, it started throwing linker errors.
$make
g++ -O0 -g3 -std=c++14 -c Army.cpp -o Army.o
g++ -O0 -g3 -std=c++14 main.cpp Army.o -o main
g++ -O0 -g3 -std=c++14 ArmyTesterMain.cpp ArmyTester.o Army.o -o ArmyTesterMain
/usr/bin/ld: ArmyTester.o: in function `ArmyTester::testa()':
/s_home/shirley/Documents/ArmyTester.cpp:23: undefined reference to `ArmyHospital::transfer() const'
/usr/bin/ld: /s_home/shirleyDocuments/ArmyTester.cpp:24: undefined reference to `ArmyHospital:: transfer() const
I made changes in the Army.cpp and Army.h files and did compile them, but ArmyTester.cpp wasn't compiled. Hence, I compiled them too by just saving the file simply.
$make
g++ -O0 -g3 -std=c++14 -c Army.cpp -o Army.o
g++ -O0 -g3 -std=c++14 main.cpp Army.o -o main
g++ -O0 -g3 -std=c++14 -c ArmyTester.cpp -o ArmyTester.o
g++ -O0 -g3 -std=c++14 ArmyTesterMain.cpp ArmyTester.o Army.o -o ArmyTesterMain
Now, it compiled all the files and the linking happened properly.
Comments
Post a Comment