c++ - Calling a macro only once in the project -
i trying set easylogging++
in project, , run following issue:
macro initialize_easyloggingpp
should called once in project. now, if call macro main.cpp
, include easylogging++.h
in main.cpp
- works fine. however, when try include easylogging++.h
in more .cpp
files, linker issues undefined references (as if macro hasn't been called). if place call macro in file alphabetically before main.cpp
, linker resolves normally. in linking phase objects sorted alphabetically.
is there nice way solve issue? or have try force different order of files @ linking time?
i not experienced sort of issues, tried googling it, couldn't find solution. if there similar question, sorry, couldn't find it.
thanks help!
maybe wrap call in function invoke using std::call_once()
, example:
void setup_logging() { static std::once_flag once; std::call_once(once, [] () { initialize_easyloggingpp(); }); }
that way can call setup_logging()
multiple times, macro invoked once.
Comments
Post a Comment