问题
I am trying to build a project using Windows 10
and Qt5.12
. The small program is using the smtp
protocol available here. I can confirm that on my Windows
I have the OpenSSL 1.1.1c 28 May 2019
.
On my Ubuntu 19.04
the same exact program compiles and run as usual but not on Windows
.
I am attaching below a print screen of the errors; however those are mostly of two types:
1) inconsistent dll linkage
2) definition of dllimport static data member not allowed
Following this link it seems that Windows
needs its "own" include (i.e. #include <windows....
) however in my case the smtp
library from the above link does not have any #include <windows>
and don't know if they have to be generated. It seems they don't from the post I found
In addition I was reading this post too because I thought I could be useful but no information was useful to help me sort out the problem
I dug more and actually went to where the windows includes
are and the following is the path I was able to find, but don't know if that could be useful:
From all the posts I red the problem seems to be, in this specific case for Windows
on how the
.pro
file is written. Below my .pro
file.
Note that I cloned this repository into my windows 10
.
.pro
QT += quick quickcontrols2 concurrent network core gui
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
TARGET = SMTPEmail
TEMPLATE = lib
DEFINES += SMTP_BUILD
win32:CONFIG += dll
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
progressbardialog.cpp \
robot.cpp \
robotmanager.cpp \
settings/emailaddress.cpp \
settings/mimeattachment.cpp \
settings/mimecontentformatter.cpp \
settings/mimefile.cpp \
settings/mimehtml.cpp \
settings/mimeinlinefile.cpp \
settings/mimemessage.cpp \
settings/mimemultipart.cpp \
settings/mimepart.cpp \
settings/mimetext.cpp \
settings/quotedprintable.cpp \
settings/smtpclient.cpp \
user.cpp \
usermanager.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
HEADERS += \
progressbardialog.h \
robot.h \
robotmanager.h \
settings/SmtpMime \
settings/emailaddress.h \
settings/mimeattachment.h \
settings/mimecontentformatter.h \
settings/mimefile.h \
settings/mimehtml.h \
settings/mimeinlinefile.h \
settings/mimemessage.h \
settings/mimemultipart.h \
settings/mimepart.h \
settings/mimetext.h \
settings/quotedprintable.h \
settings/smtpclient.h \
settings/smtpexports.h \
user.h \
usermanager.h
EDITS
To be even more specific it seems that every header the offending line is the following below:
class SMTP_EXPORT EmailAddress : public QObject // <-- SMTP_EXPORT
which leads to the smtpexports.h which I copied below:
#ifndef SMTPEXPORTS_H
#define SMTPEXPORTS_H
#ifdef SMTP_BUILD
#define SMTP_EXPORT Q_DECL_EXPORT
#else
#define SMTP_EXPORT Q_DECL_IMPORT
#endif
#endif // SMTPEXPORTS_H
ADDITIONAL EDITS
Almost all error are solved after adding DEFINES += SMTP_BUILD
but I have two errors left and I added a print screen below:
Thank you very much for pointing in the right direction on how to solve this problem.
回答1:
The files are designed to be compiled with the define SMTP_BUILD
set where the source is added, either to a library or to an executable. You have to add the
DEFINES += SMTP_BUILD
to your pro
file.
来源:https://stackoverflow.com/questions/59256699/qt5-windows-inconsistent-dll-linkage-error-and-definition-of-dllimport-stati