_decsplec (dllexport) and Ostream operations

B

Bit Byte

I have written a Dll which contains a class. I overload the "<<" opertor
in global functions to perform Ostream operations - a follows:

ostream &operator << (ostream &os, const struct _mystruct_t &ms)

However (perhaps unsuprisngly), my function is not expoted in the
DLL/lib - and when I try to build a project that uses the Dll, I get
linkage error:

demo error LNK2019: unresolved external symbol "class
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
operator<<(class std::basic_ostream<char,struct std::char_traits<char> >
&,struct _mystruct_t const &)"

Anyone knows how I can resolve this?
 
H

Holger Grund

Bit Byte said:
I have written a Dll which contains a class. I overload the "<<" opertor in
global functions to perform Ostream operations - a follows:

ostream &operator << (ostream &os, const struct _mystruct_t &ms)
Do you use __declspec(dllexport) on the definition? If not, why not?

IIRC all __declspec(dllexport) are exported even if they are
inline and not (otherwise) referenced.

-hg
 
B

Bit Byte

Holger said:
Do you use __declspec(dllexport) on the definition? If not, why not?

because the operator "<<" has a different linkage.
Anyway, I solved this by creating a static lib instead of a DLL. Builds fine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top