[SOLVED] Issue with easylogging++
-
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.