Getting two "LNK2019: unresolved external symbol" using libqrencode



  • I made a program on Qt Creator on OSX, but I'm having some issues opening the project on Windows to compile it over there. My program uses the qrencode library (http://fukuchi.org/works/qrencode/), which worked flawlessly on OSX, but I'm having trouble getting it to work here on Windows.
    After having a lot of trouble actually installing the library and getting my Qt project to find it, I'm now getting the two LNK2019 errors below:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol _QRcode_free referenced in function "private: void __thiscall MainWindow::updateQRImage(class QString)" (?updateQRImage@MainWindow@@AAEXVQString@@@Z)

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol _QRcode_encodeString referenced in function "private: void __thiscall MainWindow::updateQRImage(class QString)" (?updateQRImage@MainWindow@@AAEXVQString@@@Z)

    Here is the code that uses the library, as well as the .pro file:

    MainWindow::updateQRImage
    @
    void MainWindow::updateQRImage(QString link)
    {
    QRcode *qr = QRcode_encodeString(link.toStdString().c_str(), 1, QR_ECLEVEL_L, QR_MODE_8, 1);
    QPixmap *QRpixmap = new QPixmap(920, 920);
    QPainter painter(QRpixmap);

    if(0 != qr) {
    
        QColor fg("black");
        QColor bg("white");
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        painter.drawRect(0, 0, QRpixmap->width(), QRpixmap->height());
        painter.setBrush(fg);
        const int s = qr->width > 0 ? qr->width : 1;
        const double w = QRpixmap->width();
        const double h = QRpixmap->height();
        const double aspect = w / h;
        const double scale = ((aspect > 1.0) ? h : w) / s;
        for (int y=0; y<s; y++) {
            const int yy = y * s;
            for (int x=0; x<s; x++) {
                const int xx = yy + x;
                const unsigned char b = qr->data[xx];
                if(b &0x01){
                    const double rx1=x*scale, ry1=y*scale;
                    QRectF r(rx1, ry1, scale, scale);
                    painter.drawRects(&r,1);
                }
            }
        }
        QRcode_free(qr);
    
    }
    else{
        QColor error("red");
        painter.setBrush(error);
        painter.drawRect(0,0,width(),height());
    }
    qr = 0;
    painter.end();
    
    QPixmap *borderedQR = new QPixmap(1000, 1000);
    QPainter borderPainter(borderedQR);
    
    borderPainter.setBrush(QColor("white"));
    borderPainter.setPen(Qt::NoPen);
    borderPainter.drawRect(0, 0, borderedQR->width(), borderedQR->height());
    borderPainter.drawPixmap((borderedQR->width() - QRpixmap->width()) / 2, (borderedQR->height() - QRpixmap->height()) / 2, *QRpixmap);
    borderPainter.end();
    delete QRpixmap;
    
    this->full_QR_pixmap->swap(*borderedQR);
    delete borderedQR;
    
    
    setImageFromPixmap(*this->full_QR_pixmap, ui->lblQR);
    

    }
    @

    .pro file
    @
    #-------------------------------------------------

    Project created by QtCreator 2015-06-30T14:13:00

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

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = PlaquesMetalliques
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp
    croppingwindow.cpp
    gui_functions.cpp
    aspectratio.cpp
    misc_functions.cpp
    carddata.cpp
    catalogdialog.cpp

    HEADERS += mainwindow.h
    croppingwindow.h
    gui_functions.h
    aspectratio.h
    misc_functions.h
    carddata.h
    catalogdialog.h

    FORMS += mainwindow.ui
    croppingwindow.ui
    catalogdialog.ui

    RESOURCES +=
    defaultressource.qrc

    DISTFILES +=
    pensees.txt

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

    PRE_TARGETDEPS += $$PWD/lib/libqrencode.a

    LIBS += $$PWD/lib/libqrencode.a

    @CONFIG += debug_and_release@
    @

    Here is also the include line for the qrencode library, in mainwindow.h
    @
    #include <qrencode.h>
    @

    Does anyone know how I could go about fixing this? I've been trying to get the library to work on Windows for over a week now... :|


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you compile libqrencode with the same compiler you are using for your Qt project ? And for the same architecture ?



  • @SGaist
    I built the libqrencode library using cygwin, with the same commands I had used on OSX (the ones that are recommended on the library's webpage).
    I seem to be using different kits than on my Qt Creator on OSX though, which is most likely the source of the issue. I am using Desktop Qt 5.4.2 clang 64bit on OSX, and Desktop 5.5.0 MSVC2010 32bit on Windows. How would I go about fixing this? I don't know anything about adding new kits, and I doubt (after a quick google search) that clang can be used on Windows. :/


  • Lifetime Qt Champion

    On Windows, you can't mix compilers not even different version of Visual Studio, they are not compatible one with the other. So you have to build libqrencode with Visual Studio 2010



  • I will try to build it with Visual Studio 2010 tomorrow, and see if that helps!



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