Important: Please read the Qt Code of Conduct -

Dll link Error with static function

  • Hi everyone !

    I got this Compiler Error when Build a Shared Library (which Linked to an other Shared Library)
    This is my situation

    #include "utilities_global.h"
    class UTILITIESSHARED_EXPORT CommonFunctions
        static QString GetEnumDescription(QString className, int enumValue);

    And then I'm use it in Bussiness class like this

    QVariant valueDisplay = cf.GetEnumDescription(propColMapping.EnumType, provalue.value<int>());

    Business Project already linked to Utilities Dll

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build/Framework/Utilities/release/ -lUtilities
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build/Framework/Utilities/debug/ -lUtilities
    else:unix: LIBS += -L$$PWD/../../build/Framework/Utilities/ -lUtilities
    INCLUDEPATH += $$PWD/../Utilities
    DEPENDPATH += $$PWD/../Utilities

    Did I missing something? Or this is a limitation?
    Anyway to make it work ?!

    Thanks you very much !!!

  • If you could post the compiler error it might be more helpful but my first guess is that the method is private, you need to add public: in front of it

  • Lifetime Qt Champion

    Also, just as a note
    if its a static method, why do you call it via an instance?
    I would expect something like

    Variant valueDisplay = CommonFunctions::GetEnumDescription(xxx);

  • My mistake...!!!

    I'm trying to convert old Static Library to Shared Library.
    But I forgot to remove

    CONFIG += staticlib

    @VRonin : Issues List show something like this:

    //error: undefined reference to `_imp___ZN15CommonFunctions18GetEnumDescriptionE7QStringi'

    @mrjj : I'm try to call it with instance but it doesn't work too.

  • Qt Champions 2017

    @Dong said in Dll link Error with static function:

    Issues List show something like this:
    //error: undefined reference to `_imp___ZN15CommonFunctions18GetEnumDescriptionE7QStringi'

    You have a linker error. Make sure you have exported the function (it must be in the public section of the exported class) and that you have properly set the linker's additional libraries (the LIBS variable).

    Kind regards.

  • @kshegunov Thanks you !
    I'm already found the problem which mentioned in my reply above !

    Many Thanks !

Log in to reply