【问题标题】:C2252 Error when building log4cxxC2252 构建 log4cxx 时出错
【发布时间】:2013-08-21 18:58:50
【问题描述】:

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

运行配置和配置-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

任何想法我应该怎么做?

【问题讨论】:

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


【解决方案1】:

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

删除这个:

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

【讨论】:

    【解决方案2】:

    查看此错误报告: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>; \
    

    【讨论】:

    • LOGCXX-366 上的链接补丁建议也添加“#include
    • solution 这个帖子帮助我摆脱了流沙..
    【解决方案3】:

    这个错误是由于 VC++ 中的一个可以解决的错误。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 2013-01-03
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 2012-03-30
      相关资源
      最近更新 更多