Can't link an external C dll
-
Hello,
I have trouble linking an external C dll into a QtCreator project.
In the library I'm using, I have a folder "include" containing some .h files, a folder "lib", containing only one .def file, and also have one .dll.My .pro looks like that:
CONFIG+=console CONFIG+=c++11 CONFIG-=app_bundle CONFIG-=qt DEF_FILE+="C:\MyLib\lib\MyLib.def" INCLUDEPATH+=C:\MyLib\include LIBS+=-LC:\MyLib\lib SOURCES+=\ main.cpp include(deployment.pri) qtcAddDeployment()
However, at compilation time, I have a lot of errors : "LNK2001: unresolved external symbol ..."
These errors appear for the functions appearing in the .def file.I don't know what else I can do... I have very few experience linking library in QtCreator.
Thanks for your help
-
LIBS+=-LC:\MyLib\lib -lMyLib
You also have to tell the compiler to use the
MyLib
library with-lMyLib
argument -
Hi Florian,
the .def file contains the names of the exported function in the .dll.
To get a .lib for importing in you project as Christopher suggested you need the lib-Tool
from Microsoft Visual Studio.
Once you have Visual Studio you can open a "Visual Studio Command Prompt" and typelib.exe /def:C:\MyLib\lib\MyLib.def /OUT:C:\MyLib\lib\MyLib.lib
-
Thank you very much to both of you, it's almost working perfectly.
Now I only have two warnings:
LNK4070: /OUT:Mylib.dll directive in .EXP differs from output filename 'debug\ProjectName.exe'; ignoring directive
And in red it's written: File not found: ProjectName.expI get MyLib.exp using lib.exe, that I put in the lib folder (I'm pretty sure it's not useful there), but it seems I also need a ProjectName.exp ?
The second warning is even more weird to me:
LNK4086: entrypoint '_mainCRTStartup' is not __stdcall with 12 bytes of arguments; image may not runAny idea of what could be the problem?
EDIT: It seems to be okay now. I just remove the line "DEF_FILE+="C:\MyLib\lib\MyLib.def"" from my .pro, and everything seems to be working now :)
Thank you again,
Florian