【发布时间】: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__
main.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
main.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),当您编译您的库时会生成该文件。 -
我重写了它,但仍然是同样的错误。感谢您的建议