Reputation: 601
I have a class that has basic functionality - a couple of members and a couple of getters/setters for the same.
//xyzFile.h
class MACRO_DLL_EXPORT xyz
{
public:
bool getStatus() {return status;}
void setStatus(bool currstatus) {status = currstatus;}
.
.
.
private:
bool status;
.
.
.
};
Hence I just have this class declared and defined in a .h file and have no .cpp file. When I export this class and try using it in another dll, I get all kind of linker errors. When I just introduce an empty .cpp file, all these errors are fixed. From what I have tried understanding so far, it is because without a .cpp file, we do not have an obj file and hence linking has problems. Is this right?
Upvotes: 1
Views: 161
Reputation: 73366
Yes it is right:
If in your DLL project you don't have a .cpp, there will be no generation of a DLL. Hence all your linking with the dll will.
However, in your .h you have all the code necessary: so would'nt you have the linker dependencies, would the code compile.
For building DLL for classes, it would be safer to put in your header only the class specification, without the implementation of the functions. Put the function implementation in the .cpp of the library.
Upvotes: 1