C2252 Error when building log4cxx

2.6k views Asked by At

Building in Visual Studio 2012, APR 1.4.8 APR-UTIL 1.5.2 Log4cxx 0.10

ran configure and configure-apr

then open in VS and got 111 C2252 errors (it comes from a macro):

//
//   pointer and list definition macros when building DLL using VC
//
#if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
#define LOG4CXX_PTR_DEF(T) \
template class LOG4CXX_EXPORT log4cxx::helpers::ObjectPtrT<T>; \
typedef log4cxx::helpers::ObjectPtrT<T> T##Ptr
#define LOG4CXX_LIST_DEF(N, T) \
template class LOG4CXX_EXPORT std::allocator<T>; \
template class LOG4CXX_EXPORT std::vector<T>; \
typedef std::vector<T> N

Any ideas what should I do with this ?

3

There are 3 answers

0
Dani On BEST ANSWER

Looks like deleting the 2 lines that starts with "template" solves this.

remove this:

template class LOG4CXX_EXPORT std::allocator<T>; \
template class LOG4CXX_EXPORT std::vector<T>; \
2
drtf On

Have a look at this bug report: LOGCXX-366.

A summery of the workaround:

Edit /src/main/cpp/stringhelper.cpp, add:

#include <iterator>

Edit /src/main/include/log4cxx/log4cxx.hw , delete The following lines:

template class LOG4CXX_EXPORT std::allocator<T>; \
template class LOG4CXX_EXPORT std::vector<T>; \

extern template class LOG4CXX_EXPORT std::allocator<T>; \
extern template class LOG4CXX_EXPORT std::vector<T>; \
0
Merav Kochavi On

This error is due to a bug in VC++ which can be worked around.

  1. Move all macros outside (above) the class they are in. LOG4CXX_LIST_DEF macro is used to define classes. All macros reported in error C2252 will need to move out of any classes. This may also include moving definitions which are used in the macro.
  2. Next, change all LoggingEvent::KeySet to KeySet (this is no longer nested in a parent class)

For a full answer on how to compile Log4cxx in Visual Studio 2013 on a Windows OS see my full answer here: https://stackoverflow.com/a/36737721/3637582