Qt5-Windows:不一致的dll链接错误和dllimport静态数据成员的定义不允许 [英] Qt5 - Windows : inconsistent dll linkage error and definition of dllimport static data member not allowed
问题描述
我正在尝试使用 Windows 10
和 Qt5.12
建立一个项目。该小程序正在使用似乎是 Windows
需要它的自己的包含(即 #include< windows ....
),但是在我的情况下, smtp
上面链接中的库没有任何 #include< windows>
,并且不知道是否必须生成它们。看来他们不是我发现的帖子
此外,我正在阅读这篇文章也是,因为我认为我可能会有用,但没有信息对您有帮助我解决了问题
我挖了更多东西,实际上去了 windows包括
的位置,以下是我能够找到的路径,但是不知道这是否有用:
在我发帖的所有帖子中,问题似乎都存在,在这种情况下,对于 Windows
有关
.pro
文件的编写方式。在我的 .pro
文件下面。
请注意,我将此存储库克隆到了 windows 10
中。
.pro
QT + = quick quickcontrols2并发网络核心gui
CONFIG + = c ++ 11
#以下定义使您的编译器在使用
时发出警告#任何Qt功能已被标记为已弃用(确切的警告
#取决于您的编译器)。请参阅不推荐使用
#的API的文档,以了解如何从中移植代码。
定义+ = QT_DEPRECATED_WARNINGS
目标= SMTPEmail
模板= lib
定义+ = SMTP_BUILD
win32:CONFIG + = dll
#如果使用过时的API,您也可以使代码无法编译。
#为此,请取消注释以下行。
#您还可以选择仅在特定版本的Qt之前禁用已弃用的API。
#DEFINES + = QT_DISABLE_DEPRECATED_BEFORE = 0x060000#禁用所有在Qt 6.0.0之前弃用的API +
SOURCES + = \
main.cpp \
progressbardialog。 cpp \
robot.cpp \
robotmanager.cpp \
settings / emailaddress.cpp \
settings / mimeattachment.cpp \
settings / mimecontentformatter .cpp \
设置/mimefile.cpp \
设置/mimehtml.cpp \
设置/mimeinlinefile.cpp \
设置/mimemessage.cpp \
设置/mimemultipart.cpp \
设置/mimepart.cpp \
设置/mimetext.cpp \
设置/quotedprintable.cpp \
设置/ smtpclient。 cpp \
user.cpp \
usermanager.cpp
资源+ = qml.qrc
#用于解析QML模块的附加导入路径在Qt Creator的代码模型中
QML_IMPORT_PATH =
#用于为Qt快速设计器解析QML模块
QML_DESIGNER_IMPORT_PATH =
HEADERS + = \
progressbardialog.h \
robot.h \
robotmanager .h \
设置/ SmtpMime \
设置/emailaddress.h \
设置/mimeattachment.h \
设置/mimecontentformatter.h \
settings / mimefile.h \
settings / mimehtml.h \
settings / mimeinlinefile.h \
settings / mimemessage.h \
settings / mimemultipart.h \ \
设置/mimepart.h \
设置/mimetext.h \
设置/quotedprintable.h \
设置/smtpclient.h \
设置/smtpexports.h \
user.h \
usermanager.h
编辑
更具体地讲,似乎每个有问题的标头如下:
class SMTP_EXPORT EmailAddress:public QObject //<-SMTP_EXPORT
会导致 smtpexports.h ,我在下面复制了该文件:
#ifndef SMTPEXPORTS_H
#定义SMTPEXPORTS_H
#ifdef SMTP_BUILD
#定义SMTP_EXPORT Q_DECL_EXPORT
#else
#定义SMTP_EXPORT Q_DECL_IMPORT
#endif
#endif // SMTPEXPORTS_H
附加编辑
添加 DEFINES + = SMTP_BUILD
后,几乎所有错误都得到解决,但是我还有两个错误,我在下面添加了一个打印屏幕:
非常感谢您为解决此问题指明了正确的方向。
文件设计为使用定义的 SMTP_BUILD
设置进行编译,在该设置中将源添加到库或可执行文件中。您必须添加
定义+ = SMTP_BUILD
到 pro
文件中。
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.
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.
这篇关于Qt5-Windows:不一致的dll链接错误和dllimport静态数据成员的定义不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!