Compiling with external library failed "Cannot load library...
-
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.
-
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. -
Hi,
Out of curiosity, why are you using QLibrary to use ftd2xx ?
-
From my experience, it could be one of the following three (four) problems:
- The runtime linker cannot find the library, because it is neither in the working directory of the executable nor in the
PATH
- The executable has another architecture (32 vs. 64 bit) than the library
- The library has further dependencies that cannot be found (same as problem 1) or have different architecture (problem 2)
- You are mixing debug and release libraries
Regards
- The runtime linker cannot find the library, because it is neither in the working directory of the executable nor in the
-
... and if you are really lucky, you have a library with the wrong arch in the
PATH
that is found before the correct one. -
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
-
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 :-)