wxChar wxStringCharType error

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Earned a small fee
Earned a small fee
Posts: 23
Joined: Mon Nov 26, 2007 3:58 pm

wxChar wxStringCharType error

Post by BlueHazzard »

this is somehow a crosspost from the Code::Blocks forum (http://forums.codeblocks.org/index.php/ ... #msg119969).
I try to compile C::B in Linux Mint 12 with wx2.9.3
But i get the following error:

Code: Select all

/trunk/src/include/logmanager.h|24|error: cannot convert ‘const wxStringCharType* {aka const char*}’ to ‘const wxChar* {aka const wchar_t*}’ in assignment|
from this source:

Code: Select all

    inline wxString F(const wxChar* msg, ...)
        va_list arg_list;
        va_start(arg_list, msg);
// in wx >=  2.9 unicode-build (default) we need the %ls here, or the strings get
// cut after the first character
        ::temp_string = msg;
        ::temp_string.Replace(_T("%s"), _T("%ls"));
        msg = ::temp_string.wx_str();
        ::temp_string = wxString::FormatV(msg, arg_list);

        return ::temp_string;
line 24 is

Code: Select all

msg = ::temp_string.wx_str();

a search in the wx docs brings this:

Code: Select all

xStringCharType is defined to be:

    char when wxUSE_UNICODE==0
    char when wxUSE_UNICODE_WCHAR==0 and wxUSE_UNICODE==1
    wchar_t when wxUSE_UNICODE_WCHAR==1 and wxUSE_UNICODE==1

The wxUSE_UNICODE_WCHAR symbol is defined to 1 when building on Windows while it's defined to 0 when building on Unix, Linux or OS X. (Note that wxUSE_UNICODE_UTF8 symbol is defined as the opposite of wxUSE_UNICODE_WCHAR.)

Code: Select all

wxChar is defined to be

    char when wxUSE_UNICODE==0
    wchar_t when wxUSE_UNICODE==1 (the default).
So the error seems legit, because i build wx with Unicode so wxChar is wchar_t but because i'm on linux the String Base is char.
so how can i fix this problem? recompile wx with wxUSE_UNICODE_WCHAR=1 ?
Why is on linux in unicode builds wxChar a wchar_t and not a char?
A general question:
On linux Unicode is UTF-8 or? so can i use char or wchar_t?

sry for my bad english, i hope my questions are somehow understandable ;)
Can't get richer than this
Can't get richer than this
Posts: 733
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxChar wxStringCharType error

Post by Manolo »

Form the docs:
const wxStringCharType* wxString::wx_str() const
Explicit conversion to C string in the internal representation (either wchar_t* or UTF-8-encoded char*, depending on the build).
The wxString internal representation in Unix has been for a long time a char sequence, encoded in UTF8 (as GTK does).
So, you may try to recompile with wxUSE_UNICODE_WCHAR==1.

Anyhow, I know this internal representation has been changed (wx294 or wx-svn, I don't remember) to use wchar_t.
I would try with wx-svn.
Post Reply