," type="hidden"/>

使用log4cplus時遇到的鏈接錯誤:無法解析的外部符號 "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string ,


#include "stdafx.h"
#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
#include <log4cplus/fileappender.h>  
#include <log4cplus/win32debugappender.h>
#include <log4cplus/layout.h> 
#include <memory>
#include <log4cplus/consoleappender.h>
#include <log4cplus/tchar.h>

using namespace log4cplus;
using namespace log4cplus::helpers;

int _tmain(int argc, _TCHAR* argv[])
{
    log4cplus::initialize();
    Logger logger = Logger::getInstance(_T("main.log"));    
    //std::wstring log_path = _T("d:\\test.log");
    SharedObjectPtr<Appender> _append (new ConsoleAppender());
    
    //step 1

    
    return 0;
}

 

error LNK2019: 無法解析的外部符號 "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z),該符號在函數 _wmain 中被引用
1>D:\GetFileIcon\Rand\Debug\log4cpptest.exe : fatal error LNK1120: 1 個無法解析的外部命令

 

由於我的導入庫lib,以及動態庫dll都是正確加載的,所以不是庫沒正確加載的問題。

分析:這是由於當前工程項目的“字符集”設置與log4plus所用的“字符集”不一致所導致的,log4cplus是使用多字節字符集,而當前工程是使用 Unicode 字符集

解決方案:打開項目屬性頁-常規-字符集,改成“多字節字符集”。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM