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

error LNK2019 on implementing a third party library



  • I am trying to implement a third party library in my Qt5 project on Windows 64-bit. This third party, DuckDB provides me a dll file and a class implementation file. Since, on Windows we need a *.lib file to link in the .pro file, I have used MSVC 2019 dumpbin to get the same after following the instructions mentioned on https://asawicki.info/news_1420_generating_lib_file_for_dll_library.

    I have run qmake , deleted the debug directory before rebuilding the project and copying the duckdb.dll inside the folder after rebuild, But, I keep getting the following error. What am I doing wrong?

    duckcrud.obj : error LNK2019: unresolved external symbol "public: __cdecl duckdb::Connection::Connection(class duckdb::DuckDB &)" (??0Connection@duckdb@@QEAA@AEAVDuckDB@1@@Z) referenced in function "public: __cdecl DuckCRUD::DuckCRUD(class QObject *)" (??0DuckCRUD@@QEAA@PEAVQObject@@@Z)
    duckcrud.obj : error LNK2019: unresolved external symbol "public: __cdecl duckdb::Connection::~Connection(void)" (??1Connection@duckdb@@QEAA@XZ) referenced in function "public: virtual __cdecl DuckCRUD::~DuckCRUD(void)" (??1DuckCRUD@@UEAA@XZ)
    main.obj : error LNK2001: unresolved external symbol "public: __cdecl duckdb::Connection::~Connection(void)" (??1Connection@duckdb@@QEAA@XZ)
    duckcrud.obj : error LNK2019: unresolved external symbol "public: __cdecl duckdb::DuckDB::DuckDB(char const *,struct duckdb::DBConfig *)" (??0DuckDB@duckdb@@QEAA@PEBDPEAUDBConfig@1@@Z) referenced in function "public: __cdecl DuckCRUD::DuckCRUD(class QObject *)" (??0DuckCRUD@@QEAA@PEAVQObject@@@Z)
    duckcrud.obj : error LNK2019: unresolved external symbol "public: __cdecl duckdb::DuckDB::~DuckDB(void)" (??1DuckDB@duckdb@@QEAA@XZ) referenced in function "int `public: __cdecl DuckCRUD::DuckCRUD(class QObject *)'::`1'::dtor$1" (?dtor$1@?0???0DuckCRUD@@QEAA@PEAVQObject@@@Z@4HA)
    main.obj : error LNK2001: unresolved external symbol "public: __cdecl duckdb::DuckDB::~DuckDB(void)" (??1DuckDB@duckdb@@QEAA@XZ)
    debug\Test.exe : fatal error LNK1120: 4 unresolved externals
    

    Test.pro

    QT += quick
    
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
            duckcrud.cpp \
            main.cpp
    
    HEADERS += \
        duckcrud.h \
        duckdb.hpp
    
    RESOURCES += qml.qrc
    
    QML_IMPORT_PATH =
    
    QML_DESIGNER_IMPORT_PATH =
    
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    LIBS += -L$$PWD/./ -lduckdb
    

    DuckCRUD.h

    #ifndef DUCKCRUD_H
    #define DUCKCRUD_H
    #include <QObject>
    #include <QDebug>
    
    #include "duckdb.hpp"
    
    class DuckCRUD : public QObject
    {
        Q_OBJECT
    public:
        explicit DuckCRUD(QObject *parent = nullptr);
    
    
    private:
        duckdb::DuckDB db;
        duckdb::Connection con;
    
    };
    
    #endif // DUCKCRUD_H
    

    DuckCRUD.cpp

    #include "duckcrud.h"
    
    DuckCRUD::DuckCRUD(QObject *parent) : QObject(parent),
        db(nullptr), con(db)
    {
    }
    

    I have created a gist on github for duckdb.hpp (its
    huge file and could not be pasted here. I will delete this private gist after the problem is resolved)


  • Lifetime Qt Champion

    The header of the library is wrong

    #ifdef _WIN32
    #define DUCKDBAPI __declspec(dllexport)
    #define DUCKDBCALL __cdecl
    #else
    

    When using the library, DUCKDBAPI must be __declspec(dllimport). I would create a bug report for in the duckdb bugtracker.



  • @Christian-Ehrlicher thanks. Can you also post the link to the bug thread here so that I can follow as well



  • @Christian-Ehrlicher Also, I have changed the section in the duckdb.hpp file. But still I get the same error


  • Lifetime Qt Champion

    @chilarai said in error LNK2019 on implementing a third party library:

    But still I get the same error

    The linker errors must be different now (same functions, other decoration)

    /Edit: looked at the dll - it's missing the exports for the classes above. Nothing we can do against, ask the author of the lib.



  • I was thinking the same but thanks for confirming my suspect. I will use the same thread to report the bug if you already have done so.


Log in to reply