Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Compiling with external library failed "Cannot load library...

Compiling with external library failed "Cannot load library...

Scheduled Pinned Locked Moved Solved 3rd Party Software
9 Posts 4 Posters 469 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.
  • A Offline
    A Offline
    Antonhermann79
    wrote on last edited by aha_1980
    #1

    Hello,

    i have to use the ftdi library D2xx.lib in my QT project.
    For this I made a simple test project to learn how to use this lib.
    I'm unsing QT 6.8.1 on windows 11 in the following configuration:

    .PRO file:

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    
    DEFINES += FTD2XX_STATIC
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        3rdPatry/ftd2xx.h \
        mainwindow.h
    
    FORMS += \
        mainwindow.ui
    
    DISTFILES += \
            3rdParty/ftd2xx.lib
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./release/ -lftd2xx
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./debug/ -lftd2xx
    else:unix: LIBS += -L$$PWD/./ -lftd2xx
    
    INCLUDEPATH += $$PWD/3rdParty
    DEPENDPATH += $$PWD/3rdParty
    LIBS += -L$$PWD/3rdParty -lftd2xx
    
    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/3rdParty/libftd2xx.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/3rdParty/libftd2xx.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/3rdParty/ftd2xx.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/3rdParty/ftd2xx.lib
    else:unix: PRE_TARGETDEPS += $$PWD/3rdParty/libftd2xx.a
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    QT_BEGIN_NAMESPACE
    namespace Ui {
    class MainWindow;
    }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
        void slLoadLibrary();
    
    private:
        Ui::MainWindow *ui;
    
        char OutputBuffer[16];			//Buffer to hold MPSSE commands
        char InputBuffer[16];			//Buffer to hold read bytes
    
    
    };
    #endif // MAINWINDOW_H
    
    

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include "ftd2xx.h"
    #include<windows.h>
    
    #include <QDebug>
    #include <QLibrary>
    #include <QMessageBox>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->setWindowTitle(" uCtMOS SPI Interface Testprogramm");
        setParent(parent);
    
        QLibrary library("ftd2xx.lib");
        if(!library.load())
            qDebug() << library.errorString();
        if(library.load())
            qDebug() << "library loaded";
    
        statusBar()->showMessage(tr("uCtMOS SPI test bereit"));
    
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    

    In the setup I selected the kit with the MSCV2022 64 Bit compiler.
    I' shure using the static amd64 version of ftd2xx.lib.

    My probelm is: When executing/debugging this simple application I got the message from the application/debugging output:
    "Cannot load library ftd2xx.lib: %1 ist keine zulässige Win32-Anwendung."

    Searching in Google gave me some information but unfortunately nothing which helps me to resolve my problem loading the library.

    Because I'm not very familiar with windows applications I'm a littel lost about what's going wrong...

    Thank you for your help.

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, on Windows QLibrary can only load .dlls, not .libs, that is probably why you get the error.
      Look for a ftd2xx.dll...

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Antonhermann79
        wrote on last edited by
        #3

        Hi,

        I deleted the static ftd2xx.lib in the 3rdParty - path and copied the ftd2xx64.dll and the corresponding ftd2xx.lib there...
        ... but got the same error message.
        For the next test I renamed the fdt2xx64.dll to fdt2xx.dll but same result.

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Did you also change to
          QLibrary library("ftd2xx..dll");
          in your code?

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

            Hi,

            Out of curiosity, why are you using QLibrary to use ftd2xx ?

            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
            • aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #6

              From my experience, it could be one of the following three (four) problems:

              1. The runtime linker cannot find the library, because it is neither in the working directory of the executable nor in the PATH
              2. The executable has another architecture (32 vs. 64 bit) than the library
              3. The library has further dependencies that cannot be found (same as problem 1) or have different architecture (problem 2)
              4. You are mixing debug and release libraries

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              1
              • aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                ... and if you are really lucky, you have a library with the wrong arch in the PATH that is found before the correct one.

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Antonhermann79
                  wrote on last edited by
                  #8

                  Hi,

                  why I'm using QLibrary - the right question to resolve my problem!
                  I saw QLibrary in a code snipplet of a apperently similar case and tought this is the solution without thinking deeper...
                  But in deed I want a static linking so QLibrary isn't necessary to use.
                  Thanks for this advice (and of course the others, too) which leads me to the (simple) solution...

                  So basically I made the correct configuration in the .pro file.
                  But the consequences of the silly using a code snipplet confused me.
                  Deleting the code with QLibrary and the rest is working as expected.

                  So the probelm is solved!
                  Thank's a lot for your help.

                  Kind Regards

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

                    Good !
                    Then please mark the thread as solved using the Topic Tool button or the three dotted menu beside the answer you deem correct so other forum members may know a solution has been found :-)

                    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
                    • A Antonhermann79 has marked this topic as solved on

                    • Login

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