[英]Qt - Help Linking Dynamic Library
I am having a ton of trouble with the simple task of linking a DLL to my Qt project. 将DLL连接到我的Qt项目的简单任务我遇到了很多麻烦。
My steps: 我的步骤:
calc
method to my mylibrary.h . calc
方法添加到我的mylibrary.h中 。 calc
method in my mylibrary.cpp . calc
方法。 .a
and .dll
files were created. .a
和.dll
文件的目录。 C:/Users/Me/includes
, as well as MyLibrary.dll
and libMyLibrary.a
to C:/Users/Me/
. C:/Users/Me/includes
,以及MyLibrary.dll
和libMyLibrary.a
复制并粘贴到C:/Users/Me/
。 I add the include path as well as the DLL path: 我添加了包含路径以及DLL路径:
INCLUDEPATH += "C:/Users/Me/includes"
LIBS += "C:/Users/Me/MyLibrary.dll"
I then go into my mainwindow.cpp
, and put this code: 然后我进入我的
mainwindow.cpp
,并输入以下代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "mylibrary.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MyLibrary myLib;
qDebug() << myLib.calc();
}
MainWindow::~MainWindow()
{
delete ui;
}
And of course, I get undefined errors: 当然,我得到了未定义的错误:
C:\Users\Me\Desktop\TestInternals-Win\..\TestInternals\mainwindow.cpp:15: error: undefined reference to `_imp___ZN13MyLibrary4calcEv'
C:\Users\Me\Desktop\TestInternals-Win\..\TestInternals\mainwindow.cpp:15: error: undefined reference to `_imp___ZN13MyLibrary4calcEv'
:-1: error: collect2: ld returned 1 exit status
mylibrary.h contents: mylibrary.h内容:
#ifndef MYLIBRARY_H
#define MYLIBRARY_H
#include "MyLibrary_global.h"
class MYLIBRARYSHARED_EXPORT MyLibrary{
public:
MyLibrary();
int calc();
};
#endif // MYLIBRARY_H
mylibrary.cpp contents: mylibrary.cpp内容:
#include "mylibrary.h"
MyLibrary::MyLibrary()
{
}
int calc()
{
return 5;
}
I have not touched the Qt generated MyLibrary_global.h file 我没有触及Qt生成的MyLibrary_global.h文件
Thanks for any help. 谢谢你的帮助。
You define a stand alone calc
function instead of MyLibrary::calc
, try: 您定义一个独立的
calc
函数而不是MyLibrary::calc
,尝试:
mylibrary.cpp mylibrary.cpp
#include "mylibrary.h"
MyLibrary::MyLibrary()
{
}
int MyLibrary::calc()
{
return 5;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.