bluetiger9 / SmtpClient-for-Qt

An SMTP Client writen in C++ for Qt. Allows applications to send emails (MIME with text, html, attachments, inline files, etc.) via SMTP. Supports SSL and SMTP authentication.
https://github.com/bluetiger9/SmtpClient-for-Qt/wiki
GNU Lesser General Public License v2.1
449 stars 226 forks source link

Unresolved external symbols (Qt 6.6.1 / MSVC2019 64bits) #156

Closed fverneau closed 1 month ago

fverneau commented 4 months ago

Hello, I compiled the library with Qt 6.6.1 and MSVC2019 and I obtained two files "SmtpMime2.dll" and "SmtpMime2.lib". Everything is OK so far.

In my project, I added the following lines in my .PRO:

DEFINES += SMTP_MIME_LIBRARY win32: LIBS += -L$$PWD/smtp/ -lSmtpMime2 INCLUDEPATH += $$PWD/smtp DEPENDPATH += $$PWD/smtp

For information, the .LIB and the .DLL are in an "smtp" subdirectory of my project.

The file "main.cpp" contains :

include ".\smtp\src\SmtpMime"

NB : The files .h and .cpp of SmtpClient are in .\smtp\src\ subdirectory of my project.

When I compile my project, I get these error messages:

main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual cdecl MimeByteArrayAttachment::~MimeByteArrayAttachment(void)" (??1MimeByteArrayAttachment@@UEAA@XZ) reference in the function "public: virtual void * cdecl MimeByteArrayAttachment::`vector deleting destructor'(unsigned int)" (??_EMimeByteArrayAttachment@@UEAAPEAXI@Z) => OK, solved, in .PRO of SmtpClient it is necessary to add : SOURCES += \ ... mimebytearrayattachment.cpp \

HEADERS += \ ... mimebytearrayattachment.h \

main.obj:-1: error: LNK2019: unresolved external symbol "public: static struct QMetaObject const SmtpClient::staticMetaObject" (?staticMetaObject@SmtpClient@@2UQMetaObject@@B) referenced in function "public: static class QString __cdecl SmtpClient::tr(char const ,char const ,int)" (?tr@SmtpClient@@SA?AVQString@@PEBD0H@Z)

=> partially solved : add QObject:: in front staticMetaObject in file "SmtpClient.cpp" :

ifdef QT_NO_DEBUG

// Emit stateChanged signal only for non-internal states
if (state <= DisconnectingState) {
    emit stateChanged(state);
}

else

// emit all in debug mode
qDebug() << "[SmtpClient] State:" << QObject::staticMetaObject.enumerator(QObject::staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state);
emit stateChanged(state);

endif

What is missing ? Thank you very much in advance for your help

bluetiger9 commented 4 months ago

Hi @fverneau! :slightly_smiling_face: I committed the fix for the missing files on the v2.0 branch.

I'm not really sure about the 2nd problem. Those two methods, .staticMetaObject() and .tr(), I think are supposed to be Qt generated. So, I would check whether Qt actually generates them and adds them to the DLL.

fverneau commented 3 months ago

Hi @bluetiger9, staticMetaObject et tr depend of QObject. Is there a problem with the QObject class ? Thank you very much for your help

fverneau commented 3 months ago

Hi, Despite all my efforts, I still have this problem : main.obj:-1: error: LNK2019: unresolved external symbol "public: static struct QMetaObject const SmtpClient::staticMetaObject" (?staticMetaObject@SmtpClient@@2UQMetaObject@@B) referenced in function "public: static class QString __cdecl SmtpClient::tr(char const ,char const ,int)" (?tr@SmtpClient@@SA?AVQString@@PEBD0H@Z) The DLL cannot be used in another project at this time. Any help would be welcome.