Linker Problem with Msvc
Thiago Macieira
thiago at kde.org
Mon Dec 19 19:59:44 GMT 2005
Christian Ehrlicher wrote:
>Hi,
>
>once again an ugly linker problem with Msvc and kio (class MetaData in
>global.h). It's the same like described here:
>http://lists.trolltech.com/qt-interest/2005-12/thread00622-0.html
And again it's caused by the fact that the MS compiler & linker don't
properly understand the concept of common functions and weak symbols. The
C++ standard allows for this, so both the linker and dynamic linker in
Win32 platforms should be modified to allow for them.
The problem here is akin to inline functions and I wouldn't be surprised
if it showed up with them. A function is defined in one .h and exported
from it (__declspec(dllexport)). It is inlined in two different objects
or shared objects. Therefore, both export the function.
When linking (statically or dynamically), the linker is expected to merge
those two functions. This isn't happening.
As a side note, gcc has a switch called -fvisibility-inlines-hidden for
similar issues.
>According to the reporter, I have to define something similar to this:
>#ifdef Q_OS_WIN
>template class __declspec(dllimport) QMap<QString, QString>;
>#endif
Which is ugly.
Can't you add a simple, forward declaration using Q_CORE_EXPORT? I.e.,
lose the #ifdef and replace the __declspec with Q_CORE_EXPORT.
In fact, come to think of it, one could propose to make ALL forward
declarations include the proper EXPORT attribute. I am not sure if this
would be wise, since classes can change libraries and this would require
updating the header files (all of them) when it happened.
But we could do it for all the templates, though.
>But before I add this ugly hack, I wanted to know if MetaData has to be
>exported or not. If not, I could skip this.
>Or has someone another idea to fix this?
It's possible to do without a new class called MetaData. We can simply
typedef QMap<QString, QString> to it and move the operator+= to a
non-member function.
BTW, shouldn't we be using a QHash instead?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
4. And æfter se scieppend ingelogode, he wrát "cenn", ac eala! se
rihtendgesamnung andswarode "cenn: ne wát hú cennan 'eall'. Ástynt."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051219/1d9d8733/attachment.sig>
More information about the kde-core-devel
mailing list