Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2314838
  • 博文数量: 527
  • 博客积分: 10343
  • 博客等级: 上将
  • 技术积分: 5565
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-26 23:05
文章分类

全部博文(527)

文章存档

2014年(4)

2012年(13)

2011年(19)

2010年(91)

2009年(136)

2008年(142)

2007年(80)

2006年(29)

2005年(13)

我的朋友

分类: WINDOWS

2008-04-08 21:57:20

写烦了手工往文件里 log东西, 想找一个c/c++的可重用方案, 盯上了log4cplus, 跟log4cpp差不多, 主要是看这两个哪个名声更燥, 哪个更活跃. 可惜的是, 名声都有一些, 但都不活跃, 使用起来绝不容易.

以前在VS2003下已经编译过, 编译成.DLL, 但实际使用时引发难以解决的异常被迫放弃, 切换到VS2008上开发后, 又一次经历自己手写log代码, 心一横更冲一次.

没料想更多的麻烦, 编译器报告STL相关的错误几乎比随机生成一些ASCII单词好不到哪去, 下面是我在VS2008上编译出的两处错误:
__value,  前面两个下划线, 作者显然没有遵循前面有一个或两个下划线是保留字的规则. 这在C++/CLI里真的变成了现实, 它现在是保留字了. 这个简单, 替换即可.

另一个错误是编译 stringhelper.cxx 文件产生的, 好在这个文件不大, 错误产生在下面这个函数上:

log4cplus::tstring
log4cplus::helpers::toUpper(const log4cplus::tstring& s)
{
    tstring ret;
    std::transform(s.begin(), s.end(),
                   string_append_iterator<tstring>(ret),
#ifdef UNICODE
# if (defined(__MWERKS__) && defined(__MACOS__))
                   std::towupper);
# else
                   ::towupper);
# endif
#else
                   ::toupper);
#endif

    return ret;
}


错误信息大概是:

在google上尝试不同的关键字, 最终以
error C2039: 'iterator_category' : is not a member
搜到


其中MVP Carl Daniel 写到:
For the specific error you're seeing, insert the following line of code into
\include\log4cplus\helpers\stringhelper.h, line 123:

typedef std::output_iterator_tag iterator_category;

在特定行插入特定的代码!要命了, 对于不熟STL如我者, 要想自己抠索出来这么一个结论实在太难.

亏了log4cplus数年来无人经营, March 4th, 2007发的贴子到现在找到第123行还是没有变化, 按图索骥, 编译通过.

接下来还会有什么痛苦经验还不知道, 目前这个东东给我的教训是:
* 千万小心那些你不熟悉的技术, 比如STL, 使用这些技术, 或者使用基于这些技术的代码都是有风险的
* 谨慎对待那些有一定声誉的东西, 比如log4cplus, 真的象广告上说的那样好么, 还是自己亲自试用了再说

对于那些同样要修改123的朋友们: 我这里给个上下文



typedef _Container container_type;
            typedef void value_type;
            typedef void difference_type;
            typedef void pointer;
            typedef void reference;
            //typedef std::output_iterator_tag iterator_category;


            explicit string_append_iterator(_Container& __x) : container(&__x) {}

阅读(2209) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

jcyangzh2012-10-24 10:14:36

2012.10.24 现在最新的版本已经可以正常编译了,不会出什么错了(test on msvc11 )