Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using log4cplus & anyrpc with unicode #25

Open
JanPlitzkow opened this issue Oct 24, 2016 · 1 comment
Open

Problems using log4cplus & anyrpc with unicode #25

JanPlitzkow opened this issue Oct 24, 2016 · 1 comment

Comments

@JanPlitzkow
Copy link
Contributor

JanPlitzkow commented Oct 24, 2016

Hi,

if I figured it correctly, anyrpc-logging is not working with unicode enabled.

Log4cplus itself supports unicode, for example I was building (on Win7 64bit, VS2015) with

cmake -DBUILD_SHARED_LIBS:BOOL=TRUE -DWITH_UNIT_TESTS=OFF -DLOG4CPLUS_BUILD_TESTING=OFF -DUNICODE=ON -DLOG4CPLUS_BUILD_LOGGINGSERVER=OFF -DLOG4CPLUS_SINGLE_THREADED=ON

However setting up anyrpc via

cmake -DBUILD_EXAMPLES=OFF -DBUILD_WITH_LOG4CPLUS=ON -DBUILD_WITH_WCHAR=ON -DBUILD_WITH_THREADING=ON -DUNICODE=ON -DLOG4CPLUS_LIBRARY_RELEASE=....\log4cplus\build\src\Release\log4cplusU.lib -DLOG4CPLUS_LIBRARY_DEBUG=....\log4cplus\build\src\Debug\log4cplusUD.lib

leads to a project file, that can't be compiled (note that I provided the correct libs from log4cplus, however you might need to manually add the UNICODE preprocessor define to anyrpc project).

When compiling the anyrpc-project one gets multiple errors like

binary operator '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

or

'TimeLogger::TimeLogger(const TimeLogger &)' : cannot convert argument n from 'const char [1]' to 'log4cplus::tstring &'.

These errors are caused by calling log4cplus-macros, which obviously expect wchar (or corresponding strings) when compiled with UNICODE-preprocessor define. However the calls by anyrpc are done with simple chars, often fixed strings like "this is an example".

One solution for this problem would be, to use something like TCHAR and _T("my example") (these two only exist in Visual Studio as far as I know), but one would need to change all the logs accordingly.

For myself I found another "solution": In fact I don't really want unicode-logging, but I need the unicode-define enabled in my main project, because it is working with QT and QT needs unicode. So I just compile the dlls for anyrpc & log4cplus without UNICODE-preprocessor defined. In order to include correct headers in my main project, I changed the following lines in logger.h:

# ifdef UNICODE
# undef UNICODE
# define UNICODE_DISABLED_BECAUSE_ANYRPC_LOGGING_WITH_UNICODE_NOT_SUPPORTED
# endif
# include <log4cplus/log4cplus.h>
# define InitializeLogger() \

log4cplus::Initializer initializer; \
log4cplus::PropertyConfigurator config(LOG4CPLUS_TEXT("log4cplus.properties")); \
config.configure();

# ifdef UNICODE_DISABLED_BECAUSE_ANYRPC_LOGGING_WITH_UNICODE_NOT_SUPPORTED
# undef UNICODE_DISABLED_BECAUSE_ANYRPC_LOGGING_WITH_UNICODE_NOT_SUPPORTED
# define UNICODE
# endif

Obviously this is neither the cleanest nor a general solution, but this way UNICODE is defined everywhere (where QT needs it) except for the anyrpc / log4cplus part.

Any comments on this topic? Maybe I missed a point or there is a better way to get anyrpc running with unicode?

@sgieseking
Copy link
Owner

This seems like a reasonable short term fix. This issue can be left open until a more complete investigation and solution can be determined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants