Hi again,
in the last days I did some extensive investigations on my problem.
Let me first mention some facts about /MT and /MD and DLL creation:
* It is normally no problem to create a DLL compiled with /MT.
* The EXE which uses this DLL *should* be then also compiled with /MT
to prevent strange effects from happening. These effects are described
here <http://msdn2.microsoft.com/en-us/library/ms235460.aspx>.
* A DLL interface can be designed in a way these effects do not occur.
HOWEVER, one will run into a huge linkage problem IF one compiles a
DLL with /MT AND the DLL interface contains classes which are derived
from C(++)-std-lib's classes (like std::string, std::ostream etc.).
Exactly this is the case in MySQL++: The Query class is derived from
std::ostream, which leads to linkage errors LNK2005 and LNK1169 when
trying to link the MySQL++ DLL with the main program's EXE.
(All links and works correctly if all is compiled with /MD.)
Could anybody help me please?
I am not able to compile my main program's EXE with /MD, because I
need to link MFC statically.
I cannot compile MySQL++ with /MT because then the described "strange
effects" (including corrupt stack, crash when calling CDateTime::str()
etc.) occur.
When I link MySQL++ statically all works, but this is not allowed due
to LGPL restrictions.
Thank you for help in advance!
With best regards,
O. Baum
2008/4/22 O. Baum <oli.b@stripped>:
> Hi all,
>
> is it possible to compile the MySQL++ library so I can use it in an
> application that needs to be built as "MFC in a static library" and
> "Multithreaded (/MT)"?
>
> My build environment: MS VC 7.1.6030 (VS2003), WinXP, MySQL 5.0.58 commercial.
>
> My problem:
> If I compile MySQL++ as "Multithreaded DLL (/MD)" it does not link
> with my application (getting lots of unresolved externals linker
> errors of STL stuff like
> ---8<--------------
> error LNK2019: unresolved external symbol '"__declspec(dllimport)
> public: void __thiscall std::basic_ostream<char,struct
> std::char_traits<char> >::_Osfx(void)"
> (__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ)',
> used in function '"public: __thiscall std::basic_ostream<char,struct
> std::char_traits<char> >::sentry::~sentry(void)"
> (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ)'
> --->8--------------
> ).
>
> If I compile MySQL++ as "Multithreaded (/MT)" it links but my
> application crashes when Calling the str() methods of Query and
> DateTime instances when leaving the current scope.
> You can easily verify this by compiling just the mysqlpp-Project as
> "/MT" and add
> ---8<--------------
> mysqlpp::DateTime dt( 2008, 04, 22, 12, 22, 22 );
> string qstr = dt.str();
> cout << "test: " << dt << std::endl;
> --->8--------------
> to simple2.cpp.
>
> Strangely, if I compile excommon and simple2 as "Multithreaded (/MT)"
> it also does not link, although all should fit together in that case.
>
> I would be very glad if anybody could shed some light on this issue(s)...
>
> Thanks in advance,
>
> -oli-
> (O. Baum)