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] Issue with easylogging++
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Issue with easylogging++

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 13.3k Views 1 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    You can simplify this
    @QMAKE_CXXFLAGS += -std=c++11@

    by

    @CONFIG += c++11@

    Tested the lib on OS X and it built fine

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #5

      A quick look in the source reveals that the symbols you're missing are created via jungle-like macro expansion triggered via single call to the initialization macro.

      Do you have this call after the include?
      @
      _INITIALIZE_EASYLOGGINGPP
      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HellFighter
        wrote on last edited by
        #6

        [quote author="SGaist" date="1402955945"]You can simplify this
        @QMAKE_CXXFLAGS += -std=c++11@

        by

        @CONFIG += c++11@
        [/quote]

        Thanks, I was wondering is the same or not.

        [quote author="Chris Kawa" date="1402962115"]Do you have this call after the include?
        @
        _INITIALIZE_EASYLOGGINGPP
        @[/quote]

        Yes I did this in my precompiled header and got a lot of errors on compile.
        Now I tried to add a header file and macro initialization directly in main.cpp and it worked!

        But why I can't do this in my stdafx.h? It can not be included twice but compiler shows a lot of reinitialization errors.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #7

          Precompiled header is usually included in all of your sources so no wonder it spews redefinition errors. The symbols in question are declared as "extern" so it's ok to include that header in multiple places but the definition should be in a single .cpp and certainly not in a header that gets included everywhere (like stdafx.h). You can put it in some header but you'd have to make sure it doesn't get included in multiple files.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HellFighter
            wrote on last edited by
            #8

            [quote author="Chris Kawa" date="1402996374"]You can put it in some header but you'd have to make sure it doesn't get included in multiple files.[/quote]

            Why include guard like
            @#ifndef STDAFX_H
            #define STDAFX_H

            ...
            #include "Logger/easylogging++.h"
            _INITIALIZE_EASYLOGGINGPP

            #endif // STDAFX_H@

            does not help?

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #9

              Consider this example:
              @
              //foo.h
              #ifndef FOO_H
              #define FOO_H
              int bar;
              #endif

              //aaa.cpp
              #include "foo.h"

              //bbb.cpp
              #include "foo.h"

              //main.cpp
              #include "foo.h"
              int main() {}
              @

              Even though you have include guards, "bar" is instantiated in every .cpp file. They don't know about or include each other so in none of them FOO_H is defined initially. At the time of compilation it's ok but then linker sees bar symbol in 3 different translation units (main, aaa and bbb) and gives up.

              foo.h is essentially your stdafx.h
              int bar is your _INITIALIZE_EASYLOGGINGPP

              Edit: This will work ok:
              @
              //foo.h
              #ifndef FOO_H
              #define FOO_H
              extern int bar;
              #endif

              //aaa.cpp
              #include "foo.h"

              //bbb.cpp
              #include "foo.h"

              //main.cpp
              #include "foo.h"
              int bar;
              int main() {}
              @
              and that's what this library is doing.

              Btw. That's why we need modules in C++ so badly and I can't wait enough for the ISO committee to finish the work on them ;)

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HellFighter
                wrote on last edited by
                #10

                Chris Kawa, thank you. I clearly understand your example :)
                But can you help me in my case? I need easylogging++.h to be included in lots of my .h and .cpp files and I don't want it to be compiled every time. So I put it in my precompiled header.
                How could I achive my goals?

                1. Logger included and used in any quantity of files
                2. Logger initialized only 1 time
                3. Logger compiles only when it changes, never I suppose :)
                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Put #include "Logger/easylogging++.h" in stdafx.h
                  Put _INITIALIZE_EASYLOGGINGPP in stdafx.cpp

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    HellFighter
                    wrote on last edited by
                    #12

                    Chris Kawa,
                    Oh God ... I apologize for the stupidity ...)) I'm new in working with precompiled heders :)
                    Thank you very much :)

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      HellFighter
                      wrote on last edited by
                      #13

                      "Problem" solved.

                      1 Reply Last reply
                      0
                      • Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        No problem. They confused the bejesus out of me at first too ;)
                        Please put [SOLVED] in the title of this thread.

                        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