Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Statical linked library - undefined reference
QtWS25 Last Chance

[SOLVED] Statical linked library - undefined reference

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moravas
    wrote on last edited by
    #1

    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.

    logging.h
    @
    class Logging {
    public: static void init() {
    if(logObject == nullptr) {
    logObject = new Logging();
    logObject->logFile.setFileName(logObject->timeStamp.toString());
    logObject->logFile.open(QIODevice::WriteOnly | QIODevice::Text);
    logObject->stream.setDevice(&logObject->logFile);

        }
    }
    

    private: static Logging* logObject;
    };
    @

    logging.cpp
    @
    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 to debugging::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?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moravas
        wrote on last edited by
        #3

        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.

        Regards,
        Norbert

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved