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. Qt-created dll does not import into Qt-created app?

Qt-created dll does not import into Qt-created app?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 339 Views
  • 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.
  • D Offline
    D Offline
    dpe3
    wrote on last edited by
    #1

    I'm using:

    • QtCreator 10.0.2
    • Qt 6.2.9
    • cmake-based projects (since that seems to be the default)
    • Windows 10

    I'm trying to figure out how to create a dll in one project which is then used by another. All projects are created using "Create Project" in the QtCreator.

    My dll is a simple LibHello with one class (Hello). At this point it doesn't do anything - it's just the skeleton code that QtCreator put there. It builds to a LibHello.dll.

    My application is HelloUser - a Qt widgets based application. The only addition from the skeleton is that I've added a QPushButton and connected it signal to a private slot. The slot just creates and destroys a Hello object from the LibHello library.

    My CMakeLists.txt has the following to support using the dll:

    INCLUDE_DIRECTORIES(D:/play/hello/LibHello)
    
    unset(HELLO CACHE)
    FIND_LIBRARY(HELLO
        NAMES "LibHello.dll"
        PATHS D:/play/hello/build-LibHello-Desktop_x86_windows_msvc2019_pe_64bit-Debug
    )
    
    target_link_libraries(HelloUser PRIVATE ${HELLO})
    

    But this doesn't work. In fact, it doesn't even complete configuring cmake; it says that it couldn't find the library. Well, the file is definitely there.

    If I change FIND_LIBRARY to FIND_FILE, then it configures cmake, but when I try to build, it gives a a "LINK1107: invalid or corrupt file: cannot read at 0x348" and the error indicator references the dll file by path.

    If I change the line 'NAMES "LibHello.dll"' to 'NAMES "LibHello.lib"' then it seems to work. But I think the .lib would be for static linking and I'm looking for dynamic linking.

    Since I've used all the skeletons from QtCreator, it already has the __declspec(dllexport/dllimport) stuff in place.

    Can anyone thing of anything else that might be causing the issue?

    Thanks in advance,
    -Dan

    C 1 Reply Last reply
    0
    • D dpe3

      I'm using:

      • QtCreator 10.0.2
      • Qt 6.2.9
      • cmake-based projects (since that seems to be the default)
      • Windows 10

      I'm trying to figure out how to create a dll in one project which is then used by another. All projects are created using "Create Project" in the QtCreator.

      My dll is a simple LibHello with one class (Hello). At this point it doesn't do anything - it's just the skeleton code that QtCreator put there. It builds to a LibHello.dll.

      My application is HelloUser - a Qt widgets based application. The only addition from the skeleton is that I've added a QPushButton and connected it signal to a private slot. The slot just creates and destroys a Hello object from the LibHello library.

      My CMakeLists.txt has the following to support using the dll:

      INCLUDE_DIRECTORIES(D:/play/hello/LibHello)
      
      unset(HELLO CACHE)
      FIND_LIBRARY(HELLO
          NAMES "LibHello.dll"
          PATHS D:/play/hello/build-LibHello-Desktop_x86_windows_msvc2019_pe_64bit-Debug
      )
      
      target_link_libraries(HelloUser PRIVATE ${HELLO})
      

      But this doesn't work. In fact, it doesn't even complete configuring cmake; it says that it couldn't find the library. Well, the file is definitely there.

      If I change FIND_LIBRARY to FIND_FILE, then it configures cmake, but when I try to build, it gives a a "LINK1107: invalid or corrupt file: cannot read at 0x348" and the error indicator references the dll file by path.

      If I change the line 'NAMES "LibHello.dll"' to 'NAMES "LibHello.lib"' then it seems to work. But I think the .lib would be for static linking and I'm looking for dynamic linking.

      Since I've used all the skeletons from QtCreator, it already has the __declspec(dllexport/dllimport) stuff in place.

      Can anyone thing of anything else that might be causing the issue?

      Thanks in advance,
      -Dan

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      When you have built a dynamic library with the Microsoft compiler you get two files:

      • Blah.dll, the dynamically loadable runtime library. This ships with the executable.
      • Blah.lib, a stub library (an "import library") used by the linker to resolve names to entry points in the dynamic library to allow completion of your application binary. This file is not shipped with the executable.

      It is the second file your linker needs.

      With MingW the import library will be named blah.dll.a.
      You can probably specify the library name without the suffix and CMake will do the right thing.

      D 1 Reply Last reply
      1
      • C ChrisW67

        When you have built a dynamic library with the Microsoft compiler you get two files:

        • Blah.dll, the dynamically loadable runtime library. This ships with the executable.
        • Blah.lib, a stub library (an "import library") used by the linker to resolve names to entry points in the dynamic library to allow completion of your application binary. This file is not shipped with the executable.

        It is the second file your linker needs.

        With MingW the import library will be named blah.dll.a.
        You can probably specify the library name without the suffix and CMake will do the right thing.

        D Offline
        D Offline
        dpe3
        wrote on last edited by
        #3

        @ChrisW67 , got it, thanks!

        1 Reply Last reply
        0

        • Login

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