gpt4 book ai didi

c++ - Qt5-Windows : inconsistent dll linkage error and definition of dllimport static data member not allowed

转载 作者:行者123 更新时间:2023-11-28 01:14:08 25 4
gpt4 key购买 nike

我正在尝试使用 Windows 10 构建项目和 Qt5.12 .小程序使用的是smtp协议(protocol)可用 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

errors

正在关注 this link似乎Windows需要它的“自己的”包含(即 #include <windows.... )但是在我的例子中是 smtp上述链接中的图书馆没有任何 #include <windows>并且不知道是否必须生成它们。从我找到的帖子看来他们没有

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

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

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后几乎所有错误都解决了但我还有两个错误,我在下面添加了一个打印屏幕:

error

非常感谢您指出正确的方向来解决这个问题。

最佳答案

这些文件被设计为使用添加源的定义 SMTP_BUILD 集进行编译,可以是库或可执行文件。你必须添加

DEFINES += SMTP_BUILD

到您的 pro 文件。

关于c++ - Qt5-Windows : inconsistent dll linkage error and definition of dllimport static data member not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59256699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com