gpt4 book ai didi

c++ - 在 Qt 中使用库

转载 作者:行者123 更新时间:2023-11-30 02:42:15 24 4
gpt4 key购买 nike

我的问题可能看起来是一个真正的重复,但是我检查了很多相关的问题,我的问题仍然存在。

我找到并编译一个名为SMTPEmail的项目,所以我有我的 .dll.lib目录下的文件 Libraries/SMTPClient/debugLibraries/SMTPClient/release .

enter image description here

emailadress.h 的情况下,当我尝试在示例中包含头文件时: #include <emailaddress.h>#include <SMTPEmail/emailaddress.h> ,我收到错误无法打开包含文件“emailaddress.h”。 Q_DECL_EXPORT头文件中使用了修饰符。

SMTPEmail.pro:

...
QT += core network

TARGET = SMTPEmail

TEMPLATE = lib

DEFINES += SMTP_BUILD

win32:CONFIG += dll

QMAKE_CXXFLAGS += -fPIC
...

MyProject.pro:

...

INCLUDEPATH += ./Libraries/SMTPClient/debug

DEPENDPATH += ./Libraries/SMTPClient/debug

win32:LIBS += ./Libraries/SMTPClient/debug/SMTPEmail.lib
...

我也试过:

LIBS += -L./Libraries/SMTPClient/debug/ -lSMTPEmail

LIBS += -L$$_PRO_FILE_PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail

LIBS += -L$$PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail

LIBS += -L./MyProject/Libraries/SMTPClient/release/ -lSMTPEmail

我唯一没有做的就是将库中的头文件复制或链接到我的应用程序?

我有一种强烈的感觉,我在某处错过了一小步,你能帮我指出我做错了什么吗?

最佳答案

我认为你的问题(至少)是这一行:

INCLUDEPATH += ./Libraries/SMTPClient/debug

我几乎可以肯定,这不是可以找到 header 的包含路径的正确路径,包括 emailadress.h

您已经详细解释了您尝试过的 LIBS 值以及 lib 路径,但是您收到的是来自编译器的包含错误,而不是来自链接器的库的链接问题。我建议找出 header 的位置并将其添加到包含路径,如下所示:

# This is just pseudo code, but you need something like this
INCLUDEPATH += $$PWD/Includes/SMTPClient

回答您的问题:

The only thing that I didn't to is copying the header files which should be inside the library, is that right?

这取决于你的意思。如果你的意思是库是否应该是自包含的,那么答案是否定的,除非你使用手动符号解析等动态库加载,我不推荐简单的情况。

如果您的意思是,它随您尝试重用的项目一起提供,那么当然可以,这就是为什么您需要在项目中将 includepath 指定为该路径。

关于c++ - 在 Qt 中使用库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27293345/

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