VS2013中的Log4cplus链接错误2001 [英] Log4cplus link error 2001 in VS2013

查看:151
本文介绍了VS2013中的Log4cplus链接错误2001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确保使用Unicode字符集(Debug_Unicode)将log4cplus项目编译为Dynamic Lib,并且我自己的测试项目也已设置为Unicode字符集。它们都是在调试模型下编译的。我已经阅读了很多类似的问题,但仍然无法解决这个问题......以下是我的测试代码:

  #include     Include / log4cplus / loggingmacros.h 
#include < span class =code-string> Include / log4cplus / configurator.h
#include Include / log4cplus / helpers / loglog.h
#include Include / log4cplus / helpers / stringhelper.h
#include Include / log4cplus / helpers / fileinfo.h
#include Include / log4cplus / loggingmacros.h
#include Include / log4cplus / initializer.h
#pragma comment(lib,log4cplusUD.lib)
使用 命名空间标准;
使用 命名空间 log4cplus;
使用 命名空间 log4cplus :: helpers;
int main( int argc, wchar_t * argv [])
{

cout<< LOG4CPLUS_TEXT( 输入main()...)<< ENDL;
log4cplus ::初始化初始化器;
LogLog :: getLogLog() - > setInternalDebugging( true );
Logger root = Logger :: getRoot();
尝试 {
PropertyConfigurator :: doConfigure(LOG4CPLUS_TEXT( E:\\log4cplus.properties));
Logger fileCat = Logger :: getInstance(LOG4CPLUS_TEXT( filelogger));

LOG4CPLUS_WARN(root,LOG4CPLUS_TEXT( 测试....) );
LOG4CPLUS_WARN(root,LOG4CPLUS_TEXT( 将消息写入日志....)) ;
for int i = 0 ; i< 10000; ++ i)
LOG4CPLUS_WARN(fileCat,LOG4CPLUS_TEXT( 这是一个警告......
<< i);

// 测试属性文件中的DOS EOL是否被删除。
#define TEST_TEXT LOG4CPLUS_TEXT(这是用DOS EOL进行的测试 - >)
tistringstream propsStream(
LOG4CPLUS_TEXT( text =)TEST_TEXT LOG4CPLUS_TEXT( < span class =code-string> \\\\ n
));
属性道具(propsStream);
LOG4CPLUS_ASSERT(root,
props.getProperty(LOG4CPLUS_TEXT( text) )== TEST_TEXT);
}
catch (...){
tcout<< LOG4CPLUS_TEXT( 例外......)<< ENDL;
LOG4CPLUS_FATAL(root,LOG4CPLUS_TEXT( 发生异常......));
}
http: // www.codeproject.com/Questions/ask.aspx#
cout<< LOG4CPLUS_TEXT( 退出main()...)<< ENDL;
return 0 ;
}



我只是从log4cplus中的propertyconfig_test复制这段代码,当我编译时,lib和dll文件也用Debug_Unicode编译我自己的测试项目然后发生链接错误:

错误LNK2001:未解析的外部符号  class std :: basic_ostream< wchar_t,struct std :: char_traits< wchar_t =  >>& log4cplus :: tcout 
(?tcout @ log4cplus @@ 3AAV?$ basic_ostream @ _WU?$ char_traits @ _W @ std @@@ std @@ A)
E:\ TestCode \ 1026(thttpd)\ thttpd \thttpd \thttpd.obj thttpd



刚才,我发现如果我评论这些包含tcout功能的句子,那么一切都还可以,这个关于propertyconfig_test的例子效果很好,为什么?



我是什么尝试过:



尝试每个编译的模型和字符集,阅读lo类似问题的问题

解决方案

basic_ostream @ _WU?


char_traits @ _W @ std @@@ std @@ A)
E:\ TestCode \ 01026(thttpd)\ thttpd \thttpd \thttpd.obj thttpd



刚才,我找到了如果我评论这些包含tcout功能的句子,那么一切都很好,这个关于propertyconfig_test的例子效果很好,为什么?



我有什么尝试过:



尝试每个编译的模型和字符集,阅读许多类似的问题


至少旧版本的Visual Studio没有 tcout 的定义。



在包含log4cplus头文件之前,您可能会尝试添加它们:

  #ifdef _UNICODE 
#define tcout std :: wcout
#define tcerr std :: wcerr
#else
#define tcout std :: cout
#define tcerr std :: cerr
#endif


I ensure that i compiled log4cplus project as Dynamic Lib with Unicode charset(Debug_Unicode) and my own test project also had been set to Unicode charset. Both of them compiled under debug model. I have read many similar questions but still cannot resolve this problem... Following is my test code :

#include "Include/log4cplus/loggingmacros.h"
#include "Include/log4cplus/configurator.h"
#include "Include/log4cplus/helpers/loglog.h"
#include "Include/log4cplus/helpers/stringhelper.h"
#include "Include/log4cplus/helpers/fileinfo.h"
#include "Include/log4cplus/loggingmacros.h"
#include "Include/log4cplus/initializer.h"
#pragma comment(lib, "log4cplusUD.lib")
using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;
int main(int argc, wchar_t* argv[])
{

    cout << LOG4CPLUS_TEXT("Entering main()...") << endl;
    log4cplus::Initializer initializer;
    LogLog::getLogLog()->setInternalDebugging(true);
    Logger root = Logger::getRoot();
    try {
        PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("E:\\log4cplus.properties"));
        Logger fileCat = Logger::getInstance(LOG4CPLUS_TEXT("filelogger"));

        LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Testing...."));
        LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Writing messages to log...."));
        for (int i = 0; i<10000; ++i)
            LOG4CPLUS_WARN(fileCat, LOG4CPLUS_TEXT("This is a WARNING...")
            << i);

        // Test that DOS EOLs in property files get removed.
#define TEST_TEXT LOG4CPLUS_TEXT ("this is a test with DOS EOL-->")
        tistringstream propsStream(
            LOG4CPLUS_TEXT("text=") TEST_TEXT LOG4CPLUS_TEXT("\r\n"));
        Properties props(propsStream);
        LOG4CPLUS_ASSERT(root,
            props.getProperty(LOG4CPLUS_TEXT("text")) == TEST_TEXT);
    }
    catch (...) {
        tcout << LOG4CPLUS_TEXT("Exception...") << endl;
        LOG4CPLUS_FATAL(root, LOG4CPLUS_TEXT("Exception occured..."));
    }
http://www.codeproject.com/Questions/ask.aspx#
    cout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
    return 0;
}


I'm just copy this code from "propertyconfig_test" in log4cplus, the lib and dll file is also compiled with "Debug_Unicode",when I compiled my own test project then a link error occurs:

  error LNK2001: unresolved external symbol "class std::basic_ostream<wchar_t,struct std::char_traits<wchar_t=""> > & log4cplus::tcout"
(?tcout@log4cplus@@3AAV?$basic_ostream@_WU?$char_traits@_W@std@@@std@@A)
       E:\TestCode\1026(thttpd)\thttpd\thttpd\thttpd.obj   thttpd


Just now,I found that if I comment these sentences which include the "tcout" function,then everything is OK,This example about propertyconfig_test works well,why?

What I have tried:

Try each compiled model and charset,read lots of similar questions

解决方案

basic_ostream@_WU?


char_traits@_W@std@@@std@@A) E:\TestCode\1026(thttpd)\thttpd\thttpd\thttpd.obj thttpd


Just now,I found that if I comment these sentences which include the "tcout" function,then everything is OK,This example about propertyconfig_test works well,why?

What I have tried:

Try each compiled model and charset,read lots of similar questions


At least older versions of Visual Studio have no definitions for tcout.

You might try to add them before including the log4cplus header files:

#ifdef _UNICODE 
#define tcout std::wcout 
#define tcerr std::wcerr 
#else 
#define tcout std::cout 
#define tcerr std::cerr 
#endif 


这篇关于VS2013中的Log4cplus链接错误2001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆