[SOLVED] Statical linked library - undefined reference

  • Hy People,

    I am a very larg project (thesis of my master course) and I would like to take the common stuffs in statical linked library. I have a "main" project: controlPanel and I would like to make a statical linked library project: logging. The logging project use the singleton dessign pattern: a statical instance pointer in the class and it will be initialized in the .cpp file.

    class Logging {
    public: static void init() {
    if(logObject == nullptr) {
    logObject = new Logging();
    logObject->logFile.open(QIODevice::WriteOnly | QIODevice::Text);


    private: static Logging* logObject;

    debugging::Logging* debugging::Logging::logObject = nullptr;

    If I call the init method in the main method of controlPanel project, I get the following error at linker time:

    /home/moravas/work/sw/thesisOfMSC/controlPanel-build-Desktop_Qt_5_0_1_GCC_64bit-Debug/main.o:-1: In function debugging::Logging::hardWrite(QString, debugging::logLevel const&)': /home/moravas/work/sw/thesisOfMSC/common/logging/logging.h:79: error: undefined reference todebugging::Logging::logObject'
    :-1: error: collect2: error: ld returned 1 exit status

    I have tried to set the LIBS variable in th .pro file:

    #unix:!macx: LIBS += -lhardFifo

    unix:!macx: LIBS += -L$$PWD/../common/hardFifo-build-Desktop_Qt_5_0_1_GCC_64bit-Debug/ -lhardFifo

    INCLUDEPATH += $$PWD/../common/hardFifo-build-Desktop_Qt_5_0_1_GCC_64bit-Debug
    DEPENDPATH += $$PWD/../common/hardFifo-build-Desktop_Qt_5_0_1_GCC_64bit-Debug

    unix:!macx: PRE_TARGETDEPS += $$PWD/../common/hardFifo-build-Desktop_Qt_5_0_1_GCC_64bit-Debug/libhardFifo.a

    This is the include of library in my .pro file.

    Can somebody help me?


  • What is the name of the static library containing the debugging::Logging class and are you linking it to your main.cpp?

  • Hi,

    the name of static library is "libhardFifo.a". I don't understand your second question:
    I has been added it in my .pro file of project which contains main.cpp too. I did right click on the project and select "Add library" than I get the above configuration.


Log in to reply

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