I am having a ton of trouble with the simple task of linking a DLL to my Qt project.
My steps:
calc
method to my mylibrary.h . calc
method in my mylibrary.cpp . .a
and .dll
files were created. C:/Users/Me/includes
, as well as MyLibrary.dll
and libMyLibrary.a
to C:/Users/Me/
. I add the include path as well as the DLL path:
INCLUDEPATH += "C:/Users/Me/includes"
LIBS += "C:/Users/Me/MyLibrary.dll"
I then go into my mainwindow.cpp
, and put this code:
#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:
#ifndef MYLIBRARY_H
#define MYLIBRARY_H
#include "MyLibrary_global.h"
class MYLIBRARYSHARED_EXPORT MyLibrary{
public:
MyLibrary();
int calc();
};
#endif // MYLIBRARY_H
mylibrary.cpp contents:
#include "mylibrary.h"
MyLibrary::MyLibrary()
{
}
int calc()
{
return 5;
}
I have not touched the Qt generated MyLibrary_global.h file
Thanks for any help.
You define a stand alone calc
function instead of MyLibrary::calc
, try:
mylibrary.cpp
#include "mylibrary.h"
MyLibrary::MyLibrary()
{
}
int MyLibrary::calc()
{
return 5;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.