My issue is similar to this one but I can't figure how to fix it in eclipse.
I have a wierd behavior when compiling a small program on eclipse. When I include the .cpp file at the end of the header (and remove the include of the .h in the .cpp) it compiles and otherwise not.
The class I am trying to include is in a separate project and that project is properly linked.
Here is an example:
In project Sources
file myclass.h
#ifndef MYCLASS_H_
#define MYCLASS_H_
namespace lol
{
class myclass{ public // definitions... }
}
//#include myclass.cpp //**works when I uncomment this**
#endif
file myclass.cpp
#include "myclass.h" // ** does not work unless I include my .cpp (unity build like) **
// and I don't want to include .cpp files
namespace lol{ // not funny
myclass::myclass(){
} //code ... code
}
In other project mainFile.cpp
#include "myclass.h" // works only if I include myclass.cpp at the end of myclass.h
using namespace lol;
int main(){
myclass obj = myclass(); // gives undefined reference to lol::myclass::myclass()
}
I could fix this by building everything from a makefile which is a solution I like but I need to use eclipse, sadly.
Any suggestions?
Thanks!