[SOLVED] Issue with easylogging++
-
I'm trying to add latest version of library "Easylogging++":https://github.com/easylogging/easyloggingpp to my QT Widget application.
When I adding easylogging++.h to my project I've got a lot of messages about undefined references at most about el::base::elStorage.
In my .pro file i added c++11 support and defined a macro for QT capability
@QMAKE_CXXFLAGS += -std=c++11
DEFINES += _ELPP_QT_LOGGING@What I'm doing wrong?
Here is the whole output:
@C:/Qt/Tools/mingw482_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Qt/Projects/ButtonImageTest/build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug'
g++ -Wl,-subsystem,windows -mthreads -o debug\ButtonImageTest.exe debug/main.o debug/MainWindow.o debug/qrc_buttons.o debug/moc_MainWindow.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind -LC:/Qt/5.3/mingw482_32/lib -lQt5Widgetsd -lQt5Guid -lQt5Cored
debug/main.o: In functioncrashReason': C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:5212: undefined reference to
el::base::elStorage'
debug/main.o: In functionZN2el4base9LogFormat16updateFormatSpecEv': C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:2216: undefined reference to
el::base::utils::s_currentUser'
Makefile.Debug:82: recipe for target 'debug\ButtonImageTest.exe' failed
mingw32-make[1]: Leaving directory 'C:/Qt/Projects/ButtonImageTest/build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug'
Makefile:34: recipe for target 'debug' failed
C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:2218: undefined reference toel::base::utils::s_currentUser' C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:2222: undefined reference to
el::base::utils::s_currentHost'
debug/main.o: In functionZN2el4base13LogDispatcher8dispatchEv': C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4136: undefined reference to
el::base::elStorage'
C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4138: undefined reference toel::base::elStorage' C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4139: undefined reference to
el::base::elStorage'
C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4144: undefined reference toel::base::elStorage' debug/main.o: In function
ZN2el4base14MessageBuilder10initializeEPNS_6LoggerE':
C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4238: undefined reference toel::base::elStorage' debug/main.o:C:\Qt\Projects\ButtonImageTest\build-ButtonImageTest-Desktop_Qt_5_3_0_MinGW_32bit-Debug/../easylogging++.h:4609: more undefined references to
el::base::elStorage' follow
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\ButtonImageTest.exe] Error 1
mingw32-make: *** [debug] Error 2@Windows 8.1, QT 5.3, QT Creator
-
Hi,
Not really a Qt question, you should rather ask the original author of the library.
Also, without any code, like e.g. the initialization of that lib it's really hard to help you.
-
[quote author="SGaist" date="1402867198"]Not really a Qt question, you should rather ask the original author of the library.[/quote]
You're right but author included an "example":https://github.com/easylogging/easyloggingpp/tree/master/samples/Qt/basic in which he shows that everything should work with QT and that library was tested with QT 5.
[quote author="SGaist" date="1402867198"]Also, without any code, like e.g. the initialization of that lib it's really hard to help you.[/quote]
Initialization code is the second step and on the first step I just need to include the file easylogging++.h (this is a whole library in one file).
This is realy strange. I'm doing everything like in "example":https://github.com/easylogging/easyloggingpp/tree/master/samples/Qt/basic but can't get my application to work.
-
You can simplify this
@QMAKE_CXXFLAGS += -std=c++11@by
@CONFIG += c++11@
Tested the lib on OS X and it built fine
-
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
@ -
[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.
-
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.
-
[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?
-
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_EASYLOGGINGPPEdit: 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 ;)
-
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?- Logger included and used in any quantity of files
- Logger initialized only 1 time
- Logger compiles only when it changes, never I suppose :)
-
Put #include "Logger/easylogging++.h" in stdafx.h
Put _INITIALIZE_EASYLOGGINGPP in stdafx.cpp -
Chris Kawa,
Oh God ... I apologize for the stupidity ...)) I'm new in working with precompiled heders :)
Thank you very much :) -
"Problem" solved.
-
No problem. They confused the bejesus out of me at first too ;)
Please put [SOLVED] in the title of this thread.