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

Qt Creator prompts the static library to have an unresolved external symbol but it's work well in VS



  • I has an project, like that:

    QZXing
      |----LibZXing     (Static Library)
      |----Demo         (Console Application)
    

    The LibZXing was built with none error and link success with same code in VS. When I try to build Demo, I got some unresolved externam symbol of LibZXing.

    LibZXing.pro

    QT -= core gui
    
    TEMPLATE = lib
    CONFIG += staticlib
    
    TARGET = libzxing
    
    DESTDIR = ../lib
    
    SOURCES += LibZXing.cpp \
        src/zxing/BarcodeFormat.cpp \
        ...
    
    HEADERS += LibZXing.h \
        src/zxing/BarcodeFormat.h \
        ...
    

    Demo.pro:

    QT -= core gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    TARGET = Demo
    TEMPLATE = app
    
    INCLUDEPATH += $$PWD/../LibZXing/src
    LIBS += -L../lib/ -llibzxing
    
    SOURCES += main.cpp
    
    ibzxing.lib(QRCodeReader.obj):-1: error: LNK2019: unresolved external symbol "public: __cdecl zxing::qrcode::Decoder::Decoder(void)" (??0Decoder@qrcode@zxing@@QEAA@XZ) referenced in function "public: __cdecl zxing::qrcode::QRCodeReader::QRCodeReader(void)" (??0QRCodeReader@qrcode@zxing@@QEAA@XZ)
    ...
    libzxing.lib(DataMatrixReader.obj):-1: error: LNK2019: unresolved external symbol "public: __cdecl zxing::datamatrix::Decoder::Decoder(void)" (??0Decoder@datamatrix@zxing@@QEAA@XZ) referenced in function "public: __cdecl zxing::datamatrix::DataMatrixReader::DataMatrixReader(void)" (??0DataMatrixReader@datamatrix@zxing@@QEAA@XZ)
    ...
    libzxing.lib(PDF417Reader.obj):-1: error: LNK2019: unresolved external symbol "public: class zxing::Ref<class zxing::DecoderResult> __cdecl zxing::pdf417::decoder::Decoder::decode(class zxing::Ref<class zxing::BitMatrix>,class zxing::DecodeHints const &)" (?decode@Decoder@decoder@pdf417@zxing@@QEAA?AV?$Ref@VDecoderResult@zxing@@@4@V?$Ref@VBitMatrix@zxing@@@4@AEBVDecodeHints@4@@Z) referenced in function "public: virtual class zxing::Ref<class zxing::Result> __cdecl zxing::pdf417::PDF417Reader::decode(class zxing::Ref<class zxing::BinaryBitmap>,class zxing::DecodeHints)" (?decode@PDF417Reader@pdf417@zxing@@UEAA?AV?$Ref@VResult@zxing@@@3@V?$Ref@VBinaryBitmap@zxing@@@3@VDecodeHints@3@@Z)
    ...
    qtmaind.lib(qtmain_win.obj):-1: error: LNK2019: unresolved external symbol main referenced in function WinMain
    

    Here is my project: Dropbox Share
    Thanks for your helping.


  • Lifetime Qt Champion

    @wzj1695224 Remove lib from LIBS += -L../lib/ -llibzxing

    LIBS += -L../lib/ -lzxing
    


  • @jsulm

     error: LNK1104: cannot open file 'zxing.lib'
    

  • Lifetime Qt Champion

    Hi,

    Where is libzxing.lib exactly located on your hard drive ?



  • @SGaist

    E:\Developments\Source\.build-qt-QZXing-Qt_5_7_0_MSVC_14_0\lib
    

    I had try to using absolute path, but it still have those problems.

    E:\Developments\Source
        |------.build-qt-QZXing-Qt_5_7_0_MSVC_14_0
        |          |-----------Demo (folder)
        |          |-----------lib (folder)
        |          |                |-------libzxing.lib
        |          |-----------LibZXing (folder)
        |
        |------QZXing
        |          |--------QZXing.pro
        |          |--------Demo (folder)
        |          |            |---------Demo.pro
        |          |           ...
        |          |--------LibZXing (folder)
        |          |            |---------LibZXing.pro
        |          |           ...
    

  • Lifetime Qt Champion

    Are you sure you are linking against a static version of libzxing.lib ?
    Because otherwise, it looks like the symbol are not properly tagged for export/import.



  • @SGaist
    Merry Christmas!
    Yes, the libzxing.lib Qt Creator builds is same size as VS builds
    I has share my project.
    https://www.dropbox.com/s/d9o5zyirazbruty/QZXing.zip?dl=0


  • Lifetime Qt Champion

    Your main.cpp file is faulty, it doesn't contain a main function but a mains function.



  • @SGaist
    Cause I want to test some function, so I wrote a new main function and renamed old one to mains. I forgot to change it back.
    But this is not the key to my question, is it?
    p.s. I had update the QZXing.zip


  • Lifetime Qt Champion

    No indeed, it's not the key. However, having to first debug a project before being able to trigger the bug to check what is going wrong is not really nice.


Log in to reply