My project has this folder structure:
Project/
--Classes/
----Class1.h
----Class1.cpp
--main.cpp
"Class1.h" contains method definitions, "Class1.cpp" is the source code for "Class1.h".
The source code of "Class1.h" is like this:
class Class1 {
public:
void do_something();
};
The source code of "Class1.cpp" is like this:
#include "Class1.h"
void Class1::do_something() {
//
}
The source code of "main.cpp" is like this:
#include "Classes/Class1.h"
int main(int argc,char** args) {
Class1* var = new Class1();
var->do_something();
return 0;
}
However, when compiling "main.cpp", the compiler doesn't know where the implementation of methods in Class1 is, so it shows linking error about undefined reference.
Do I have to add any path into the command line so the compiler knows what source files it has to compile? How to tell the compiler that it must compile "Class1.cpp" also?