i've tried to use this header in my qt project and get linker error:
CMakeFiles/test.dir/myerror.cpp.o: In function
`operator<<(std::basic_ostream<char,
std::char_traits<char> >&, wchar_t const*)':
/opt/google/include/glog/logging.h:1093: multiple definition of
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, wchar_t
const*)'
CMakeFiles/test.dir/xmlcheckthread.cpp.o:/usr/include/QtCore/qglobal.h:1499:
first
defined here
CMakeFiles/test.dir/myerror.cpp.o: In function
`operator<<(std::basic_ostream<char,
std::char_traits<char> >&, std::basic_string<wchar_t,
std::char_traits<wchar_t>,
std::allocator<wchar_t> > const&)':
/home/aeon/projects/shalficky/qt_client/wchar_log.h:19: multiple definition
of
`operator<<(std::basic_ostream<char, std::char_traits<char> >&,
std::basic_string<wchar_t, std::char_traits<wchar_t>,
std::allocator<wchar_t> > const&)'
CMakeFiles/test.dir/xmlcheckthread.cpp.o:/home/aeon/projects/shalficky/qt_client/wchar_log.h:19:
first defined here
including header in logging.h gives me same result.
is there any way to resolve this problem?
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Ah, I think I forgot to add "inline" for the two operators.
#ifndef WCHAR_LOGGING_H_
#define WCHAR_LOGGING_H_
#include <wchar.h>
#include <iostream>
#include <string>
inline std::ostream& operator<<(std::ostream& out, const wchar_t* str) {
size_t len = wcsrtombs(NULL, &str, 0, NULL);
char* buf = (char*)malloc(len + 1);
buf[len] = 0;
wcsrtombs(buf, &str, len, NULL);
out << buf;
free(buf);
return out;
}
inline std::ostream& operator<<(std::ostream& out, const std::wstring& str)
{
return operator<<(out, str.c_str());
}
#endif // WCHAR_LOGGING_H_
Please let me know if this doesn't solve your issue.
Issue 29 has been merged into this issue.
Ok,I try this bug-fix in my vs2008 sp1 project, and it works. well done!
why not merge this in the project?