Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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


  • Lifetime Qt Champion

    @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



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

  • Lifetime Qt Champion

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



  • @aha_1980 oh. yes.

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

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


  • Lifetime Qt Champion

    @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


Log in to reply