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. dll link doesn't work with Qt quick Application - Empty
Forum Updated to NodeBB v4.3 + New Features

dll link doesn't work with Qt quick Application - Empty

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 595 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.
  • K Offline
    K Offline
    kinn
    wrote on last edited by
    #1

    Hello,
    Qt newbie here. I am trying to use a dll on a new quick project, just to check how it works.

    As a first try I started a brand new Qt Quick Application - Empty project with the following pro file:

    QT += quick
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    INCLUDEPATH += "C:\Users\Andrea\Desktop\API\include"
    LIBS += "C:\Users\Andrea\Desktop\API\bin_dynamic\my_API.dll"
    
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc
    
    QML_IMPORT_PATH =
    
    QML_DESIGNER_IMPORT_PATH =
    
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    DISTFILES += \
        testconf.xml
    
    

    and in the main I simply call:

       api_connect();
    

    On run, the application crashes.

    I made the same test with a Qt Console Application, same links, same include, same function called: it works nicely.

    So, going back to the failed project, I appended the keyword 'console';

    QT += quick
    CONFIG += c++11 console
    

    and it works. I need to use the Qt quick project. How can I solve it?

    Thanks in advance,
    Andrea

    aha_1980A 1 Reply Last reply
    0
    • K kinn

      Hello,
      Qt newbie here. I am trying to use a dll on a new quick project, just to check how it works.

      As a first try I started a brand new Qt Quick Application - Empty project with the following pro file:

      QT += quick
      CONFIG += c++11
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      INCLUDEPATH += "C:\Users\Andrea\Desktop\API\include"
      LIBS += "C:\Users\Andrea\Desktop\API\bin_dynamic\my_API.dll"
      
      
      SOURCES += \
              main.cpp
      
      RESOURCES += qml.qrc
      
      QML_IMPORT_PATH =
      
      QML_DESIGNER_IMPORT_PATH =
      
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      DISTFILES += \
          testconf.xml
      
      

      and in the main I simply call:

         api_connect();
      

      On run, the application crashes.

      I made the same test with a Qt Console Application, same links, same include, same function called: it works nicely.

      So, going back to the failed project, I appended the keyword 'console';

      QT += quick
      CONFIG += c++11 console
      

      and it works. I need to use the Qt quick project. How can I solve it?

      Thanks in advance,
      Andrea

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @kinn said in dll link doesn't work with Qt quick Application - Empty:

      INCLUDEPATH += "C:\Users\Andrea\Desktop\API\include"
      LIBS += "C:\Users\Andrea\Desktop\API\bin_dynamic\my_API.dll"

      First of all, use forward slashes in Qt: /. Backslashes are used as line-continuation character, like in the SOURCES list.

      Second: You don't link against a dll file, you link against a .lib file. And the (portable) syntax for linking is: LIBS += -LC:/Users/Andrea/Desktop/API/bin_dynamic -lmy_API (where my_API stands for my_API.lib)

      This also makes sure, Creator adds the path to the dynamic linker so your dll is picked up at runtime.

      You should afterwards run qmake and on the following build, check the linker command line for any errors.

      Regards

      Qt has to stay free or it will die.

      K 1 Reply Last reply
      1
      • aha_1980A aha_1980

        @kinn said in dll link doesn't work with Qt quick Application - Empty:

        INCLUDEPATH += "C:\Users\Andrea\Desktop\API\include"
        LIBS += "C:\Users\Andrea\Desktop\API\bin_dynamic\my_API.dll"

        First of all, use forward slashes in Qt: /. Backslashes are used as line-continuation character, like in the SOURCES list.

        Second: You don't link against a dll file, you link against a .lib file. And the (portable) syntax for linking is: LIBS += -LC:/Users/Andrea/Desktop/API/bin_dynamic -lmy_API (where my_API stands for my_API.lib)

        This also makes sure, Creator adds the path to the dynamic linker so your dll is picked up at runtime.

        You should afterwards run qmake and on the following build, check the linker command line for any errors.

        Regards

        K Offline
        K Offline
        kinn
        wrote on last edited by
        #3

        @aha_1980 hi, thanks for your help.
        I followed you suggestions:

        • replaced backslashes with forward slashes
          -used the folllowing:
        LIBS += LC:/Users/Andrea/Desktop/API/bin_dynamic -lmy_API
        

        but it didn't work as well. In the bin_dynamic folder there are both the dll and the lib files. The error reported is:

        :-1: error: error: LC:/Users/Andrea/Desktop/API/bin_dynamic: Invalid argument
        
        aha_1980A 1 Reply Last reply
        0
        • K kinn

          @aha_1980 hi, thanks for your help.
          I followed you suggestions:

          • replaced backslashes with forward slashes
            -used the folllowing:
          LIBS += LC:/Users/Andrea/Desktop/API/bin_dynamic -lmy_API
          

          but it didn't work as well. In the bin_dynamic folder there are both the dll and the lib files. The error reported is:

          :-1: error: error: LC:/Users/Andrea/Desktop/API/bin_dynamic: Invalid argument
          
          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @kinn You missed the minus before big L: -Lpath ;)

          Qt has to stay free or it will die.

          K 1 Reply Last reply
          0
          • aha_1980A aha_1980

            @kinn You missed the minus before big L: -Lpath ;)

            K Offline
            K Offline
            kinn
            wrote on last edited by
            #5

            @aha_1980 oh. yes.

            However, I have now un undefined reference to api_connect()

            the include is there, I am missing something...

            aha_1980A 1 Reply Last reply
            1
            • K kinn

              @aha_1980 oh. yes.

              However, I have now un undefined reference to api_connect()

              the include is there, I am missing something...

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @kinn said in dll link doesn't work with Qt quick Application - Empty:

              However, I have now un undefined reference to api_connect()
              the include is there, I am missing something...

              Without further information it's hard to help here.

              Are you:

              • Using the same compiler for DLL and EXE?
              • declaring the api_connect() function as extern "C"?
              • have you checked that api_connect() is exported?

              I think best would be to have the whole project as Zip file for download somewhere. That would make the checks more easy.

              Regards

              Qt has to stay free or it will die.

              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