C2252构建log4cxx时出错

时间:2013-08-21 18:58:50

标签: c++ visual-studio-2012 build log4cxx

在Visual Studio 2012中构建, APR 1.4.8 APR-UTIL 1.5.2 Log4cxx 0.10

运行configure和configure-apr

然后在VS中打开并得到111个C2252错误(它来自一个宏):

//
//   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

任何想法我应该怎么做?

3 个答案:

答案 0 :(得分:2)

看起来删除以“template”开头的2行解决了这个问题。

删除它:

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

答案 1 :(得分:1)

查看此错误报告:LOGCXX-366

解决方法的总结:

修改 /src/main/cpp/stringhelper.cpp ,添加:

#include <iterator>

修改 /src/main/include/log4cxx/log4cxx.hw , 删除以下行:

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>; \

答案 2 :(得分:0)

  

此错误是由于VC ++中可以解决的错误造成的。

  1. 将所有宏移动到它们所在的类之外(上方)。 LOG4CXX_LIST_DEF宏用于定义类。所有的宏 报告错误C2252将需要移出任何类。这个 也可能包括在宏中使用的移动定义。
  2. 接下来,将所有LoggingEvent :: KeySet更改为KeySet(不再是这样 嵌套在父类中)
  3.   

    有关如何在Visual Studio 2013中编译Log4cxx的完整答案   Windows操作系统在这里看到我的完整答案:https://stackoverflow.com/a/36737721/3637582