Discussion:
Compiling wxWidgets with UTF8 encoding in Windows
(too old to reply)
Niels
2014-09-30 09:42:55 UTC
Permalink
Hello,

I am using Windows but it is very convenient for my projects that wxWidgets
can be encoded in UTF8 internally.

This is why, I have tried to compile wxWidgets 3.0.1 with MinGW with the
options –enable-utf8 (I know that it is supposed to be Unix only but I read
here (by Vadim Zeitlin) that it was possible as long as we knew why we
wanted it).

I have used MSYS for the compilation.

This is my configure command:

../configure –enable-debug –enable-utf8

Then the following make command returns an error:

make MONOLITHIC=1 BUILD=release DEBUG_FLAG=0

This is the error message:

../src/msw/calctrl.cpp: In member function 'bool
wxCalendarCtrl::Create(wxWindow*, wxWindowID, const wxDateTime&, const
wxPoint&, const wxSize&, long int, const wxString&)':

../src/msw/calctrl.cpp:112: error: operands to ?: have different types
'const wxScopedWCharBuffer' and 'const wchar_t [14]'

make: *** [advdll_msw_calctrl.o] Error 1

What should I do? (I also managed to compile wxWidgets without –enable-utf8
and then set wxUSE_UNICODE_UTF8 to 1, but when I compile my project, I get
linking errors of the type “undefined reference”).

Thank you very much in advance,

Niels
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-10-01 00:26:34 UTC
Permalink
On Tue, 30 Sep 2014 02:42:55 -0700 (PDT) Niels wrote:

N> This is why, I have tried to compile wxWidgets 3.0.1 with MinGW with the
N> options –enable-utf8 (I know that it is supposed to be Unix only but I read
N> here (by Vadim Zeitlin) that it was possible as long as we knew why we
N> wanted it).

Yes, but as not many people use this build, it's not really surprising
that it gets broken periodically.

N> This is the error message:
N>
N> ../src/msw/calctrl.cpp: In member function 'bool
N> wxCalendarCtrl::Create(wxWindow*, wxWindowID, const wxDateTime&, const
N> wxPoint&, const wxSize&, long int, const wxString&)':
N>
N> ../src/msw/calctrl.cpp:112: error: operands to ?: have different types
N> 'const wxScopedWCharBuffer' and 'const wchar_t [14]'
N>
N> make: *** [advdll_msw_calctrl.o] Error 1
N>
N> What should I do?

This is a bug, it should be fixed by this patch:

diff --git a/src/msw/calctrl.cpp b/src/msw/calctrl.cpp
index ac0d8bb..8b6f359 100644
--- a/src/msw/calctrl.cpp
+++ b/src/msw/calctrl.cpp
@@ -108,7 +108,7 @@ wxCalendarCtrl::Create(wxWindow *parent,
}

const wxChar * const clsname = s_clsMonthCal.IsRegistered()
- ? s_clsMonthCal.GetName().t_str()
+ ? static_cast<const wxChar*>(s_clsMonthCal.GetName().t_str())
: MONTHCAL_CLASS;

if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )


Please let me know if it works for you and if you have any other problems
building wxMSW in UTF-8 mode.

Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Niels
2014-10-01 23:52:21 UTC
Permalink
Thank you so much !!!
Your patch worked for me and I've had no more problems during the
compilation.

Unfortunately, I now still have a problem related to why I wanted to use
internal UTF8 encoding with wxWidgets with Windows:

How can I implicitly create a wxString from a char* encoded in UTF8
(without using FromUTF8() )?
Is there a way to be able to use the implicit creation of a wxString from a
char* in the current locale encoding? (now that I built wxwidgets with UTF8
internal encoding)
If so, how?

Thank you very much again in adavnce,

Niels
Post by Vadim Zeitlin
N> This is why, I have tried to compile wxWidgets 3.0.1 with MinGW with the
N> options –enable-utf8 (I know that it is supposed to be Unix only but I read
N> here (by Vadim Zeitlin) that it was possible as long as we knew why we
N> wanted it).
Yes, but as not many people use this build, it's not really surprising
that it gets broken periodically.
N>
N> ../src/msw/calctrl.cpp: In member function 'bool
N> wxCalendarCtrl::Create(wxWindow*, wxWindowID, const wxDateTime&, const
N>
N> ../src/msw/calctrl.cpp:112: error: operands to ?: have different types
N> 'const wxScopedWCharBuffer' and 'const wchar_t [14]'
N>
N> make: *** [advdll_msw_calctrl.o] Error 1
N>
N> What should I do?
diff --git a/src/msw/calctrl.cpp b/src/msw/calctrl.cpp
index ac0d8bb..8b6f359 100644
--- a/src/msw/calctrl.cpp
+++ b/src/msw/calctrl.cpp
@@ -108,7 +108,7 @@ wxCalendarCtrl::Create(wxWindow *parent,
}
const wxChar * const clsname = s_clsMonthCal.IsRegistered()
- ? s_clsMonthCal.GetName().t_str()
+ ? static_cast<const wxChar*>(s_clsMonthCal.GetName().t_str())
: MONTHCAL_CLASS;
if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
Please let me know if it works for you and if you have any other problems
building wxMSW in UTF-8 mode.
Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-10-02 14:33:12 UTC
Permalink
On Wed, 1 Oct 2014 16:52:21 -0700 (PDT) Niels wrote:

N> Thank you so much !!!
N> Your patch worked for me and I've had no more problems during the
N> compilation.

Thanks for testing, I've applied it now.

N> Unfortunately, I now still have a problem related to why I wanted to use
N> internal UTF8 encoding with wxWidgets with Windows:
N>
N> How can I implicitly create a wxString from a char* encoded in UTF8
N> (without using FromUTF8() )?
N> Is there a way to be able to use the implicit creation of a wxString from a
N> char* in the current locale encoding? (now that I built wxwidgets with UTF8
N> internal encoding)
N> If so, how?

I'm not sure. Under Unix you can set wxUSE_UTF8_LOCALE_ONLY=1 (done by
configure --enable-utf8only option) to assume that all narrow strings are
in UTF-8, but this requires UTF-8 locale. You could try setting
wxUSE_UTF8_LOCALE_ONLY for your Windows build too, but things will break as
soon as you call any CRT functions with 8-bit strings as locales never use
UTF-8 under Windows, so you *will* have nasty surprises. Using FromUTF8()
is a safer solution.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Loading...