[Solved] Making a DLL and a .lib to work with Qt



  • Hi everyone, I know this might be a very basic question, but I'm having problems using some functions present on a DLL from a barcode scanner. The reason I'm asking is because it was designed to work with old Windows versions and specially with Visual Basic & Visual C/C++ projects, so I want to be sure that the errors I'm getting have nothing to do with a missuse of the library itself.

    I've been reading some posts about this topic and so far I have this on my .pro file:

    @
    #-------------------------------------------------

    Project created by QtCreator 2014-06-05T14:57:39

    #-------------------------------------------------

    QT += core gui sql

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = transporte_ucv_harvester
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp
    sessionwindow.cpp
    logmaster.cpp
    dbconnector.cpp
    logreporter.cpp

    HEADERS += mainwindow.h
    sessionwindow.h
    logmaster.h
    dbconnector.h
    logreporter.h
    Csp32.h

    FORMS += mainwindow.ui
    sessionwindow.ui
    logreporter.ui

    RESOURCES +=
    icons.qrc
    pictures.qrc

    OTHER_FILES +=
    Csp32.def

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/include/ -lCsp32

    INCLUDEPATH += $$PWD/include
    DEPENDPATH += $$PWD/include
    @

    I also added the /include directory inside the folder where the source code is and put there the Csp32.dll and Csp32.lib files.

    Then, I put the Csp32.h in the source directory and try to run the project. It worked fine. But when I try to use one of the DLL functions, even though Qt Creator show hints for them, the compiler reports this:

    @C:\Users\fernandesp\Desktop\Proyectos\CompuSciens\UCV-Transporte\Harvester\build-transporte_ucv_harvester-Desktop-Debug\debug\mainwindow.o:-1: In function `ZN10MainWindowC2EP7QWidget':

    C:\Users\fernandesp\Desktop\Proyectos\CompuSciens\UCV-Transporte\Harvester\transporte_ucv_harvester\mainwindow.cpp:9: error: undefined reference to `_imp__cspRestore@0'

    collect2.exe:-1: error: error: ld returned 1 exit status@

    Did I miss any step on adding the library to my project? Or is something related to the library itself?

    Thanks for any help you can provide!

    Edit

    By the way, the line of code that makes it explode is:

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "Csp32.h"

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    cspRestore(); // <---- This one!!!!
    

    }
    @


  • Moderators

    The error you are getting comes from the linker, not the compiler. You have missing symbols, but the library is correctly found (otherwise it would complaing about missing library).

    My first guess is that you are compiling in 64 bits but linking a 32 bit library.



  • Hi @sierdzio, thanks for your answer. But actually I’m not… The library comes from a SDK found here http://www.tecno-symbol.com/symbol/lectores_de_codigos/symbol_cs2000/lectores_cs2000.html and I’m using a 32 bit system too.

    I’ve been reading what I think is the .cpp that generates the .dll and it requires some headers that I’m pretty sure I don’t have, but I’m not getting that error yet, I think.


  • Moderators

    This is really not about the headers: the compiler has compiled your code without any errors, so it has all the headers it needs.

    This is, as far as I can tell, about linking. If the architecture is not the reason, then maybe (although this is less probable) it's lack of compiler binary compatibility. If you can, check what compiler was used to build that library, then compare it with your compiler. If they differ (MinGW vs. MSVC, or MSVC 2010 vs. MSVC 2008), that might be the problem.

    Even less probable, but possible: the library can be compiled in different ways, by specifying various DEFINES. You need to use the same defines as the builder of that library used to make sure the binary layout of the file is the same.



  • From the "apidoc" that comes from the SDK itself:

    The CSP DLL runs under Windows ’95 / ‘98 and NT 4.0 operating systems. The DLL was created using MS Visual C/C++ V 5.0 compiler

    I'm using MinGW. So according to you, that might be the problem. I'm pretty sure that .cpp file I mentioned was the source used to compile the .dll, what do you think about building it again? I have never done that but I think it can be done...

    If there a way of fixing this without recompiling the library?


  • Moderators

    Woah, that is an oldie :)

    I think a recompilation of the library will be necessary. But maybe others will have some better ideas.



  • I see... Well, I'll try to recompile it or even use it as a cpp itself (?), while I wait for others responses.

    But almost nobody sees this category, everyone is posting at "General and Desktop.."

    By the way, thanks for your help :)


  • Moderators

    I can move it to General and Desktop. I don't know how other people are doing, but I always scan all newly posted posts, regardless of the subforum they are posted to.



  • Well actually I didn't know this category existed until I had this question hahaha. So I guess most people without much experience like me, ignores this. But I think is better to leave it here, since not everyone knows about this, so that filter should bring less but better answers.

    Once I make the library to run, I'll mark the post as Solved.



  • I ended up adapting the libraries to "modern" C++ (since it was written without the concept of classes) by modifying the .h and .cpp files that comes with the SDK and including them among the rest of my code. Everything is working now!

    I'm marking this as Solved.


  • Moderators

    Good to know, congratulations :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.