Qt Creator - Linking to an external library problem
I have been trying all day to add an external library to my Qt Project. I'm a complete nooby where it comes to compilers, libraries and linkage and I really can't seem to solve my problem.
The library I'm trying to add is named AutoItX3 and it is used for automation like simulating mouse clicks and key strokes.
I have 3 files: AutoItX3.dll, AutoItX3.lib and AutoItX3.h.
I previously tried the library in a visual studio 2012 project and it worked just fine. The only thing I did is include the AutoItX3.h and AutoItX3.lib files in my project and then copy the .dll in the debug folder where the .exe is.
Now in Qt Creator I've tried several things. I've added this to my .pro file:
LIBS += -lAutoItX3
LIBS += -LLibPath
INCLUDEPATH += IncludePath
where LibPath is the absolute path to the folder where AutoItX3.lib is contained, and IncludePath is the absolute path to the folder where AutoItX3.h is contained.
I try to call a simple function in my MainWindow constructor:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
AU3_Sleep(1000); // This function is defined in AutoItX3.h
and I keep getting this error:
@mainwindow.obj:-1: error: LNK2019: unresolved external symbol AU3_MouseClick referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)@
Could it be a problem in the .dll itself? Or maybe in the .lib?
I find it pretty strange since it works fine in visual studio...
Thanks for your help.
P.s.: I have Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB).
Hi and welcome to devnet,
Are you sure that AutoItX3 is the only library you have to link to ?
Hello SGaist, thank you for your answer!
Unfortunately, yes I am pretty sure it is the only library I have to link to, as I tried it beforehand in visual studio and it worked just fine... :(
By the way, I just noticed I posted the wrong error message. Here is the right one:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol AU3_Sleep referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
This means it can't find the symbol while linking.
One problem I can see:
LIBS += -LLibPath <= Do you have AutoItX3.lib in that folder ? Or is it a variable ?
Yes, LibPath represents the absolute path to the folder containing the .lib and IncludePath represents the absolute path to the folder containing the .h.
They are both something like this:
Thanks again for your answer!
Ok, then you need to expand LibPath with something like $$LibPath, without that your line means literally -LLibPath