Search code examples
c++boost

Getting compiler errors from including Boost LocalTime


I'm including the Boost local time library:

#include <boost/date_time/local_time/local_time.hpp>

but getting compile errors from the include. Think it's clashing with my definition of likely:

include/boost/date_time/special_values_parser.hpp:105:24: error: C++ requires a type specifier for all declarations
    static bool likely(const string_type& str)
                       ^
include/boost/date_time/special_values_parser.hpp:105:17: error: expected parameter declarator
    static bool likely(const string_type& str)
                ^
Macros.h:23:46: note: expanded from macro 'likely'
#define likely(x)       __builtin_expect((x),1)

Not really sure how to resolve this? Is there a way other than re-naming my macro? (it's used in a lot of places).


Solution

  • If your compiler supports it you could use #pragma push_macro:

    #pragma push_macro("likely")
    #undef likely
    #include <boost/date_time/local_time/local_time.hpp>
    #pragma pop_macro("likely")
    

    If that isn't an option try moving the #include to before your #define likely and if that isn't an option you very likely will need to rename the macro.