首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Visual 2015中构建log4cxx

如何在Visual 2015中构建log4cxx
EN

Stack Overflow用户
提问于 2015-07-28 14:22:56
回答 3查看 3.5K关注 0票数 2

我一直在使用log4cxx,它可以满足我的需要。我们将转到VS 2015,我发现Visual 2015中的编译器在我试图重建log4cxx 0.10.0.1时抛出了错误。如果我将项目工具集更改为Visual 2013 (v120),则构建仍然有效,但当我尝试使用它时,在运行时会出现问题。

请参阅下面的错误消息,它会在多个场合发生。有人找到用Visual 2015正确构建log4cxx的方法了吗?

代码语言:javascript
运行
复制
4>..\..\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/layout.h(90): error C2248: 'log4cxx::helpers::ObjectImpl::ObjectImpl': cannot access private member declared in class 'log4cxx::helpers::ObjectImpl'
4>..\..\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/helpers/objectimpl.h(43): note: see declaration of 'log4cxx::helpers::ObjectImpl::ObjectImpl'
4>..\..\SDKS\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/helpers/objectimpl.h(28): note: see declaration of 'log4cxx::helpers::ObjectImpl'
4>..\..\SDKS\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/layout.h(90): note: This diagnostic occurred in the compiler generated function 'log4cxx::Layout::Layout(const log4cxx::Layout &)'
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-07-30 12:20:31

我也有同样的问题,希望能找到解决办法。

问题是基类ObjectImpl的定义:

代码语言:javascript
运行
复制
    class LOG4CXX_EXPORT ObjectImpl : public virtual Object
    {
    public:
        ObjectImpl();
        virtual ~ObjectImpl();
        void addRef() const;
        void releaseRef() const;

    protected:
        mutable unsigned int volatile ref;

    private:
        //
        //   prevent object copy and assignment
        //
        ObjectImpl(const ObjectImpl&);
        ObjectImpl& operator=(const ObjectImpl&);
    };

如您所见,类隐藏副本构造函数和复制赋值操作符,因为使用引用计数器的设计没有合适的实现。最好使用共享指针。

新的stl实现对它们的集合类使用了移动语义,当没有带有move语义的复制构造函数和复制赋值操作符时,必须使用标准运算符,这些运算符是不可用的。

为了解决这个问题,我们必须将move操作符添加到以下类: ObjectImpl、Layout、Filter、PatternConverter、TriggeringPolicy和RollingPolicyBase。

下面是我对ObjectImpl的新实现:

代码语言:javascript
运行
复制
    class LOG4CXX_EXPORT ObjectImpl : public virtual Object
    {
    public:
        ObjectImpl();
        virtual ~ObjectImpl();
        void addRef() const;
        void releaseRef() const;

        // added for VS2015
        ObjectImpl(ObjectImpl && o)
        {
            ref = o.ref;
            o.ref = 0;
        }

        ObjectImpl& operator=(ObjectImpl && o)
        {
            ref = o.ref;
            o.ref = 0;

            return *this;
        }
        // -----

    protected:
        mutable unsigned int volatile ref;

    private:
        //
        //   prevent object copy and assignment
        //
        ObjectImpl(const ObjectImpl&);
        ObjectImpl& operator=(const ObjectImpl&);
    };

还有另一个例子。其余的类类似:

代码语言:javascript
运行
复制
    class LOG4CXX_EXPORT Filter : public virtual OptionHandler,
        public virtual helpers::ObjectImpl
    {
        /**
        Points to the next filter in the filter chain.
        */
        FilterPtr next;
    public:
        Filter();

        // added for VS2015
        Filter(Filter && o)
            : helpers::ObjectImpl(std::move(o))
            , next( o.next )
        { }

        Filter& operator=(Filter && o)
        {
            helpers::ObjectImpl::operator=(std::move(o));
            next = o.next;
            return *this;
        }
        // end of added for VS2015

        ...

我希望这能帮上忙。

票数 3
EN

Stack Overflow用户

发布于 2016-09-23 22:27:17

一位同事遇到了这个问题,他通过选择File > New > Project > Visual C++并选择Install Windows XP Support for C++解决了这个问题。奇怪的是,我从来没有这样做过,但我也从来没有遇到过同样的问题。

票数 1
EN

Stack Overflow用户

发布于 2021-12-07 07:20:26

下面的代码是正确的答案apache-log4cxx-0.10.0 vs2015

代码语言:javascript
运行
复制
// objectimpl.h
namespace log4cxx
{
   namespace helpers
   {
      /** Implementation class for Object.*/
      class LOG4CXX_EXPORT ObjectImpl : public virtual Object
      {
      public:
         ObjectImpl();
         virtual ~ObjectImpl();
         void addRef() const;
         void releaseRef() const;

      protected:
         mutable unsigned int volatile ref;

        //private:
                        //
            //   prevent object copy and assignment
            //
        ObjectImpl(const ObjectImpl&);
        ObjectImpl& operator=(const ObjectImpl&);
      };
   }
}

// objectimpl.cpp
ObjectImpl::ObjectImpl(const ObjectImpl& o)
{
    ref = o.ref;
    o.ref = 0;
}
ObjectImpl& ObjectImpl::operator=(const ObjectImpl& o)
{
    ref = o.ref;
    o.ref = 0;

    return *this;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31679144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档