【问题标题】:QT 5.4 errors after connection DLL连接 DLL 后出现 QT 5.4 错误
【发布时间】:2015-02-07 11:55:53
【问题描述】:

我是新来的。我想问错误在哪里。 我制作了自己的dll(通过代码块),我想在另一个 qt 项目中使用它 我设置和执行 qmake 的所有内容,但它仍然让我 LNK2019 和 LNK1120。 我附上一个代码库和qt项目

dll6.dll
main.h

using namespace std;
#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus

#endif

DLL_EXPORT void SomeFunction(const LPCSTR sometext);
DLL_EXPORT int text_pozdrav(int i);

#ifdef __cplusplus

#endif

#endif // __MAIN_H__

ma​​in.cpp

DLL_EXPORT int text_pozdrav(int i)
{
    return i;
}

使用dll3(QT) 使用dll3.pro

#-------------------------------------------------
#
# Project created by QtCreator 2015-02-06T13:47:38
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = usingdll3
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

HEADERS += \../dll6/main.h

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../dll6/bin/Debug/libdll6.a
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../dll6/bin/Debug/libdll6.a
else:unix: LIBS += -L$$PWD/../dll6/bin/Debug/ -adll6

LIBS += -LC:/Users/Jakub/Documents/Projekty/dll6/bin/Debug/dll6.dll

INCLUDEPATH += $$PWD/../dll6/bin/Debug
DEPENDPATH += $$PWD/../dll6/bin/Debug

ma​​in.cpp

#include <QCoreApplication>
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include "main.h"


using namespace std;
DLL_EXPORT int text_pozdrav(int i);

int main(int argc, char *argv[])
{    
    QCoreApplication a(argc, argv);
    cout << text_pozdrav(22) << endl;

    return a.exec();

}

错误

LNK2019: main.obj:-1: Chyba: LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl text_pozdrav(int)" (__imp_?text_pozdrav@@YAHH@Z) referenced in function _main
LNK1120: debug\usingdll3.exe:-1: Chyba: LNK1120: 1 unresolved externals

谢谢你的回答

【问题讨论】:

  • LIBS += -LC:/Users/Jakub/Documents/Projekty/dll6/bin/Debug/dll6.dll 应该有一个 .lib 文件(不是 .dll),当您编译您的库时会生成该文件。
  • 我重写了它,但仍然是同样的错误。感谢您的建议

标签: c++ qt dll


【解决方案1】:

已解决,在 Visual C++ 中用 gcc 和 qt 编译的代码块

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-13
    • 2017-09-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2017-06-26
    • 2015-06-03
    相关资源
    最近更新 更多