Unsolved How to link Qt libraries into DLL project
-
Hi,
I have a Qt DLL project that I've created to provide functionality to another application (on Windows). For this DLL to work, when I ship the DLL I need to ship Qt DLL's with it and have them in specific paths, relative to my DLL.
Is there a way I can link the relevant Qt components into my DLL so that I only need to ship the one file?
I've tried building Qt statically (both MT and MD), then using those Qt builds when building my DLL, but then the build process won't create the DLL file. (It only creates the .lib.)
(I have a Qt Commercial license. I'm using Qt 5.9.5, Visual Studio 2017 and the Visual Studio Qt Addin.)
Regards,
M -
@mjsmithers
I don't use/do any of this, but in principle you should be able to produce a DLL which links statically with (i.e. includes) the.lib
from other libraries rather than their DLL (if any).Unless someone replies better, you might need to look at/show us just what your
LINK
line is specifying.P.S.
AFAIK,/MT
&/MD
only affect which Visual C runtime LIBs vs DLLs are linked against, nothing to do with other libraries. -
Hi JonB,
Currently there is no LINK line for this DLL project.
For regular QT applications, I don't need to specify a LINK line. The necessary libraries just get linked in automatically. And this appears to be what's happening in my working DLL project, in that my project appears to link in the relevant QT .LIB files such that my DLL knows what other Qt DLL's are needed a runtime.
Are you suggesting that for Qt statically linked DLL (and LIB) projects, the LINK line needs to be explicit and list everything to be combined?
Thanks,
M -
@mjsmithers said in How to link Qt libraries into DLL project:
such that my DLL knows what other Qt DLL's are needed a runtime
I don't get this. Previously you wrote:
I've tried building Qt statically (both MT and MD), then using those Qt builds when building my DLL, but then the build process won't create the DLL file. (It only creates the .lib.)
If you are building Qt (or anything else) statically, there are no DLLs, only LIBs. The whole point of "static" is that everything gets done with LIB files at link time, so there won't be any "what DLLs are required at runtime).
As I understand it, you wish to produce a single DLL of your own code (which itself will be sought dynamically at runtime), and that DLL will already have all the Qt code "embedded" in it from the built Qt LIB file (so there will not be any Qt DLLs to be sought at runtime).
To do that you will be passing the
/DLL
argument toLINK
(https://docs.microsoft.com/en-gb/cpp/build/reference/dll-build-a-dll).I have no idea what "Visual Studio Qt Addin" does, but a VS DLL project will still have a "LINKER" tab with whatever arguments.
At which point, it might be better for me to shut up and see if someone else understands better than I, in case I'm misleading you somehow.....
-
Hi,
Since you are on windows, are you exporting your dll symbols ?
-
Yes, regarding exporting DLL symbols, I mentioned above that I already have the DLL compiling and working using the public Qt 5.9.5 download.
So after some more playing around last night, I think I solved it.
As background, the PRO file was originally created using Qt Creator and has the line TEMPLATE = lib
- When I open the PRO file using the VS addin and using the public Qt 5.9.5 (32 bit vs2015), Visual Studio shows the project target as a DLL. My compliled DLL is small and I need to ship QT DLL's with it, for it to work.
- When I open the same project using the VS addin and using my static MD build of Qt 5.9.5, Visual Studio shows the project target as a LIB (which is odd) and the linker fails with errors.
- If I add CONFIG += dll to the PRO file, then open again using the VS adding and my static MD build of Qt 5.9.5, Visual Studio shows the project target as a DLL (great!), the linker succeeds, and my resulting DLL is large (and appears to lave linked in the Qt stuff). When I now use this one DLL (with NO adjacent Qt DLLs) in the 3rd party app (which it's intended for) it works correctly - the same as the DLL from 1.
So apparently the PRO file needs CONFIG += dll to force the Visual Studio addin to set the DLL project target for some Qt builds.
Best,
M