Qt5-Windows:不一致的dll链接错误和dllimport静态数据成员的定义均不允许

问题描述 投票:0回答:1

我正在尝试使用Windows 10Qt5.12建立一个项目。小程序正在使用可用的smtp协议here。我可以确认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

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9tZkJHdWFsLnBuZyJ9” alt =“错误”>

跟随this link,似乎Windows需要其“自己的”包含(即#include <windows....),但是在我的情况下,上述链接中的smtp库没有任何#include <windows>,并且不知道是否它们必须生成。看来他们不是我发现的帖子

此外,我正在阅读this post too,因为我认为我可能有用,但没有任何信息可以帮助我解决问题

我挖了更多的东西,实际上去了windows includes的位置,以下是我能够找到的路径,但是不知道这是否有用:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9mY1BNVjhZLnBuZyJ9” alt =“包括”>

在我发的所有帖子中,问题似乎都存在,在这种情况下,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后几乎所有错误都解决了,但是我还剩下两个错误,并且在下面添加了打印屏幕:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9TamVKOW4wLnBuZyJ9” alt =“错误”>

非常感谢您为解决此问题指明了正确的方向。

c++ windows qt c++11 qt5
1个回答
0
投票

这些文件被设计为使用定义SMTP_BUILD设置进行编译,该设置将源添加到库或可执行文件中。您必须添加

DEFINES += SMTP_BUILD

到您的pro文件。

© www.soinside.com 2019 - 2024. All rights reserved.