Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to link Qt libraries into DLL project
Forum Updated to NodeBB v4.3 + New Features

How to link Qt libraries into DLL project

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjsmithers
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • M mjsmithers

      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

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mjsmithers
        wrote on last edited by
        #3

        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

        JonBJ 1 Reply Last reply
        0
        • M mjsmithers

          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

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @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 to LINK (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.....

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Since you are on windows, are you exporting your dll symbols ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mjsmithers
              wrote on last edited by mjsmithers
              #6

              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

              1. 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.
              2. 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.
              3. 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

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved