1. 程式人生 > >在VS2015中使用easylogging++新增支援Unicode

在VS2015中使用easylogging++新增支援Unicode

我在win32應用程式中使用easylogging++做日誌,字符集使用的是Unicode,預設無法輸出中文到日誌,看了http://blog.csdn.net/Fish_55_66/article/details/49451321中的介紹,試著用
  1. #define ELPP_UNICODE
  2. #include "easylogging++.h"
  3. INITIALIZE_EASYLOGGINGPP  
  4. int main(int argc, char** argv)  
  5. {  
  6.     /// 同時使用 START_EASYLOGGINGPP 才能使用Unicode 
  7.     START_EASYLOGGINGPP(argc, argv);  
  8.     LOG(INFO) << L"巨集定義演示。";  
  9.     system("pause");  
  10.     return 0;  
  1. }  

結果編譯器連結的時候報錯:

1>tijianji.obj : error LNK2001: 無法解析的外部符號 "public: virtual class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __thiscall el::base::DefaultLogBuilder::build(class el::LogMessage const *,bool)const " (

[email protected]@[email protected]@@[email protected][email protected][email protected]@@[email protected][email protected]@@[email protected]@[email protected]@[email protected])
1>E:\__wang\workspace\Projects\tijianji\Debug\tijianji.exe : fatal error LNK1120: 1 個無法解析的外部命令

是巨集INITIALIZE_EASYLOGGINGPP裡面的class DefaultLogBuilder : public LogBuilder {
public:
base::type::string_t build(const LogMessage* logMessage, bool appendNewLine) const;
};引起的。報錯應該是string_t無法識別引起的,這個型別宣告是這樣的:

#if defined(ELPP_UNICODE)
#  define ELPP_LITERAL(txt) L##txt
#  define ELPP_STRLEN wcslen
#  if defined ELPP_CUSTOM_COUT
#    define ELPP_COUT ELPP_CUSTOM_COUT
#  else
#    define ELPP_COUT std::wcout
#  endif  // defined ELPP_CUSTOM_COUT
typedef wchar_t char_t;
typedef std::wstring string_t;
typedef std::wstringstream stringstream_t;
typedef std::wfstream fstream_t;
typedef std::wostream ostream_t;
#else
#  define ELPP_LITERAL(txt) txt
#  define ELPP_STRLEN strlen
#  if defined ELPP_CUSTOM_COUT
#    define ELPP_COUT ELPP_CUSTOM_COUT
#  else
#    define ELPP_COUT std::cout
#  endif  // defined ELPP_CUSTOM_COUT
typedef char char_t;
typedef std::string string_t;
typedef std::stringstream stringstream_t;
typedef std::fstream fstream_t;
typedef std::ostream ostream_t;
#endif  // defined(ELPP_UNICODE)

我明明都定義了巨集#define ELPP_UNICODE為什麼還是無法解析?

最後靈機一動把ELPP_UNICODE新增到“前處理器定義”裡面,結果就連結通過了。