I have an <<
operator overload defined in a (VC++ 2013) DLL that compiles fine:
Definition:
__declspec(dllexport) friend std::ostream& operator<< (std::ostream& os, const ComplexMessage& rhs);
Implementation:
std::ostream& operator<< (std::ostream& os, const ComplexMessage& rhs)
{
os << rhs.toString();
return(os);
}
The dll contains another 50 methods including multiple operator overloads, which compile and link fine.
However, the program using the dll can't link the method for <<.
It declares the <<
overload as
__declspec(dllimport) std::ostream& operator<< (std::ostream& os, const ComplexMessage& rhs);
The code compiles fine. But it won't link:
error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream > & __cdecl messaging::operator<<(class std::basic_ostream > &,class messaging::ComplexMessage const &)"
All other DLL methods link fine. Does anyone know why this linker error is occurring?
EDIT This is different than the proposed duplicate question. The symbols are defined in the code of the DLL and syntactically compile; however, it doesn't link. This suggests to me that either the code for that particular operator<< overload is not being generated, or it is being generated but not correctly found. I'm sure it's something simple, but I've been banging my head on this one.