Important: Please read the Qt Code of Conduct -

QT + DLL + LIB + MSVC + unresolved externals

  • I have a header file with a function:

    __inline void foo(WCHAR * moscraciun)

    In another header I have:

    __inline __declspec(dllexport) void foo(WCHAR*);

    After compile I have: dll and lib;
    I have looked in dll and in the lib files and all functions are there decorated, everything seems ok.

    I have another header with definition:

    __inline __declspec(dllimport) void foo(WCHAR*);

    this header is metamorphic __declspc(dllimport) is preprocessor defined and converts normaly according to build specs

    in my code I am loading the lib with #pragma comment(lyb, mylib.lib), it is set in the project at additional librearies so it's ok

    I call foo() and i get:

    error LNK2019: unresolved external symbol "void __cdecl foo(unsigned short*)" (?foo_decorat) referenced in function "public: virtual void __thiscall CCLassName::MethodName" (?Method name decorated)

    The problem is that a project works with this dll and lib but it has only MFC. The one that doesn't work has Qt.

    [EDIT: code formatting, Volker]

  • an inline function can not be exported.
    You should decide, whether it is inline or exported :-)

  • The dll with the lib is compiled in visual studio. Also I am compiling the qt project in VS. When I compile a MFC project in VS everything works ok.

  • Ok, forget about the __inline. I have made a small solution with 3 projects. A c++ MFC project, a Qt project and a c++ dll project.
    Dll has a simple foo function exported with __declspecs(dllexport).
    lib shows that function.
    In dll project I have 2 headers one with the definition and one with the body.

    Now the MFC project copiles and link ok and calls foo. Qt project doesn't.

    I think I am doing something wrong.
    The Qt project was made in Qt creator, a simple project. I saved and moved all project dir in my Visual solution dir. I have imported the Qt proj using Qt addin than in project settings beside the Qt libs(core, gui etc) I have entered my lib. Also I am calling foo() in mainwindow class(in constructor) and added #include of the header with the definition of the function. Finally I have compiled but got unresolved externals.

Log in to reply