没有办法解决这个问题了吗?log4cplus在VS2005中的link错误,关于模板使用
昨天下载了一个log4cplus,这些工具类不想自己写了,用用现成的不是很好。不过首先发现最后一次修改还是2004年的,不管了,先下下来吧。
使用VS2005编译,出现几个编译错误,这个不难,google之,很快就找到了答案。
http://aspalliance.com/groups/microsoft_public_dotnet_languages_vc/ng-973873_VS2005_breaking_my_builds_.aspx
replace all occurrences of __value with something else: __value is recognized as a keyword by the VC2005 compiler (the authors of log4cpp should not have used it - all identifiers containing two consequetive underscores are reserved to the implementation).
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;
根据上面的建议修改之后,编译可以通过,但是发现一共16个工程,有一个工程无法build成功,有三个link错误。
错误内容:
1. main.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class TestThread * __thiscall log4cplus::helpers::SharedObjectPtr<class TestThread>::operator->(void)const " (__imp_??C?$SharedObjectPtr@VTestThread@@@helpers@log4cplus@@QBEPAVTestThread@@XZ),该符号在函数 _main 中被引用
2. main.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall log4cplus::helpers::SharedObjectPtr<class TestThread>::`default constructor closure'(void)" (__imp_??_F?$SharedObjectPtr@VTestThread@@@helpers@log4cplus@@QAEXXZ),该符号在函数 _main 中被引用
3. main.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall log4cplus::helpers::SharedObjectPtr<class TestThread>::~SharedObjectPtr<class TestThread>(void)" (__imp_??1?$SharedObjectPtr@VTestThread@@@helpers@log4cplus@@QAE@XZ),该符号在函数 _main 中被引用
.\thread_test_Release/thread_test.exe : fatal error LNK1120: 3 个无法解析的外部命令
于是去thread_test工程下,里面就一个main.cxx
主要就是这一句:
第83行,
log4cplus::helpers::SharedObjectPtr<TestThread> threads[NUM_THREADS];
这里无法找到,再看生成的dll文件呢,于是dumpbin一下,发现其导出是这样的。
7 6 0001CD30 ??0?$SharedObjectPtr@VAbstractThread@thread@log4cplus@@@helpers@log4cplus@@QAE@PAVAbstractThread@thread@2@@Z
怎么会这样呢?
而且经过实验,发现VC6编译能够通过,但是通过dumpbin观察,其导出函数与VS2005很不同。
继续google,找到一位和我问题差不多的
http://www.eggheadcafe.com/forumarchives/vclanguage/Aug2005/post23130691.asp
看来就是因为模板不是real code,所以dll无法根据实际情况导出,这里的class TestThread只有exe知道,所以link的时候找不到,因为没有生成嘛。而VC6,是像这句话所说
Some compilers such as VC6 assume that all template code must have all possible instantiations in the ?translation unit that it is declared in, but there's no real justification
现在我的问题就是,如何做,使得这个代码可以编译通过呢?
还是因为C++本身的语法条件局限,根本就是一个无法解决的问题呢?
多谢多谢!
PS:贪心贪心,还想问问,除了log4cplus外,是否有其他log类。
已试用log4cpp,但是似乎工程都不全,有很多.vcproject都没有,就没有搞。而且也很旧了,是2005年的。
至于log4cxx,下载的0.9.7,看介绍说有不少bug,而0.9.8因为要大改还是啥的,还没出来。
有无其他推荐?