One of my homeworks involves three files: LineType.h, LineType.cpp, and Driver.cpp. Driver.cpp contains the main() method which uses a class defined by LineType.h and LineType.cpp.
On my system, Driver.cpp starts with:
#include "LineType.h"
#include "LineType.cpp"
#include <iostream>
And the program compiles and runs perfectly when I run g++ Driver.cpp
from within the project directory via the command line. However, when my instructor attempts to compile the program (I believe she uses Eclipse), it fails to compile. After some back-and-forth, she was able to fix the problem on her end by commenting out one of the #includes from Driver.cpp:
#include "LineType.h"
//#include "LineType.cpp"
#include <iostream>
When I attempt to run g++ Driver.cpp
on this edited file, my compiler complains about "Undefined symbols for architecture", which I understand to mean that it cannot find definitions for the class/methods being called.
What are my instructor and I doing differently to cause this difference in behavior? Why does a line required by my compiler cause her compiler to fail?
#include
a cpp file. Your instructor's build system does something more likeg++ Driver.cpp LineType.cpp
(although it's better than that)