我正在尝试使用Windows 10
和Qt5.12
构建一个项目。这个小程序使用的是smtp
协议可用的这里。我可以在我的Windows
上确认我有OpenSSL 1.1.1c 28 May 2019
。在我的Ubuntu 19.04
上,相同的程序会像往常一样编译和运行,但不会在Windows
上运行。
我在打印屏幕下面附加错误,但是这些错误主要有两种类型:
1) inconsistent dll linkage
2) definition of dllimport static data member not allowed
在此链接之后,Windows
似乎需要它自己的包含(即#include <windows....
),但是在我的例子中,来自上面链接的smtp
库没有任何#include <windows>
,并且不知道是否需要生成它们。好像他们不是从我找到的那个岗位上
此外,我阅读这个帖子也是是因为我认为我可能很有用,但没有任何信息可以帮助我解决问题。
我挖了更多的东西,实际上去了windows includes
所在的地方,下面是我能够找到的路径,但不知道这是否有用:
从我发布的所有文章来看,问题似乎是,对于Windows
来说,关于.pro
文件是如何编写的。在我的.pro
文件下面。注意,我将这个存储库克隆到我的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
编辑
更确切地说,似乎每个标题--即违规行--如下所示:
class SMTP_EXPORT EmailAddress : public QObject // <-- SMTP_EXPORT
这导致了我在下面复制的smtpexports.h:
#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
附加编辑
添加DEFINES += SMTP_BUILD
之后,几乎所有的错误都得到了解决,但是我还有两个错误,我在下面添加了一个打印屏幕:
非常感谢您就如何解决这个问题指出了正确的方向。
发布于 2019-12-10 15:46:48
这些文件被设计成使用将源添加到库或可执行文件的定义SMTP_BUILD
集进行编译。您必须添加
DEFINES += SMTP_BUILD
到您的pro
文件。
https://stackoverflow.com/questions/59256699
复制相似问题