Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
smartmobili
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Dec 06, 2019 1:10 pm

Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by smartmobili »

Hi,

I am trying to compile our application by enabling the macro wxNO_IMPLICIT_WXSTRING_ENCODING but I have some errors inside wxWidgets include
D:\Stage\wxWidgets-3.1.4-msvc15-x86_64\Debug\include\wx\msgdlg.h
The problem might be due to our "ugly hack" because we override the wxGetTranslation at some point but just by looking at source code I am trying to understand how it works because there is the following code:

virtual wxString GetDefaultYesLabel() const { return wxGetTranslation("Yes"); }

the wxGetTranslation is passed a const char* (there is no wxT("")) but from what I understand since the wxString do not convert implicitely from const char* how can it work ?
To really test it I should compile a dymmy application with the macro enabled.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by stahta01 »

What wxString options was used to build the wxWidgets lib(s)?

I can try to see if GCC has the same issue; but, I am guessing the cause is wxWidgets build options.

Edit: Looks like your mods is the likely cause; after more wx code examination.

Edit2: You likely need to add changes from "* Explicit encoding for implicit conversion in wxGetTranslation()" dated 2019-10-23

Edit3: And likely the one the day before

Code: Select all

* Use wxASCII_STR() on string literals

Fix the build with wxNO_IMPLICIT_WXSTRING_ENCODING.

Tim S.
Cherry
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Apr 09, 2020 4:13 am

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by Cherry »

On my windows 10 system implicit conversion of char* to wxString always uses latin1, regardless of what code page is in effect.

On stepping through the code where I pass a char* to wxLogMessage, I see that FromAscii is invoked, and a comment in the code notes that this always uses latin1.

Who uses latin1 these days? Everyone uses utf-8

So I defined wxNO_IMPLICIT_WSTRING_ENCODING in wxWidgets/include/wx/msw/setup.h, and the log.h file would not compile, with the result that twenty or so wxWidgets modules failed to compile

This fails even if the only thing changed in setup.h is

Code: Select all

#define wxNO_IMPLICIT_WSTRING_ENCODING 1
wxWidgets commit "HEAD is now at 0bbc074095 Update binaries SHA-1 sums for 3.1.5 release too"

Windows 10, latest release of Visual Studio, unable to build wxWidgets if the release is changed by defining wxNO_IMPLICIT_WSTRING_ENCODING

Code: Select all

D:\src\wallet\wxWidgets\include\wx\log.h(984,1): error C2248: 'wxArgNormalizer<const char*>::get': cannot access private member declared in class 'wxArgNormalizer<const char*>'
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.72
  D:\src\wallet\wxWidgets\include\wx\strvararg.h(690): message : see declaration of 'wxArgNormalizer<const char*>'
  D:\src\wallet\wxWidgets\include\wx\msw\private.h(371): message : see reference to function template instantiation 'void wxLogger::Log<const char*,int,const wchar_t*,long,wxString>(const wxFormatString &,T1,T2,T3,T4,T5)' being compiled
          with
          [
              T1=const char *,
              T2=int,
              T3=const wchar_t *,
              T4=long,
              T5=wxString
          ]
  D:\src\wallet\wxWidgets\include\wx\log.h(984,1): error C2248: 'wxArgNormalizer<const char*>::get': cannot access private member declared in class 'wxArgNormalizer<const char*>'
  D:\src\wallet\wxWidgets\include\wx\strvararg.h(694): message : see declaration of 'wxArgNormalizer<const char*>::get'
  D:\src\wallet\wxWidgets\include\wx\strvararg.h(690): message : see declaration of 'wxArgNormalizer<const char*>'
  Done building target "ClCompile" in project "wx_aui.vcxproj" -- FAILED.

Done building project "wx_aui.vcxproj" -- FAILED.

Build FAILED.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by stahta01 »

You typo-ed the name of the define "wxNO_IMPLICIT_WXSTRING_ENCODING" Has WXSTRING in it; not WSTRING!

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by stahta01 »

And, adding it to "setup.h" is likely wrong!

You are supposed to according to the directions define it when building your application! Not while building the library.

Tim S.
Cherry
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Apr 09, 2020 4:13 am

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by Cherry »

Still fails if I define it in my application instead of setup.h

Code: Select all

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once
#define wxUSE_STATUSBAR 1
// For compilers that support precompilation, includes "wx/wx.h".
#define wxNO_IMPLICIT_WXSTRING_ENCODING 1
#include <wx/wxprec.h>
#include <wx/cmdline.h>
Visual studio gives the same error as with it defined in setup.h

1> H:\wallet\wxWidgets\include\wx\log.h(979,1): error C2248: 'wxArgNormalizer<const char*>::get': cannot access private member declared in class 'wxArgNormalizer<const char*>'
1> H:\wallet\wxWidgets\include\wx\strvararg.h(694): message : see declaration of 'wxArgNormalizer<const char*>::get'
1> H:\wallet\wxWidgets\include\wx\strvararg.h(690): message : see declaration of 'wxArgNormalizer<const char*>'
1> H:\wallet\wxWidgets\include\wx\msw\private.h(371): message : see reference to function template instantiation 'void wxLogger::Log<const char*,long,const wchar_t*,long,wxString>(const wxFormatString &,T1,T2,T3,T4,T5)' being compiled
1> with
1> [
1> T1=const char *,
1> T2=long,
1> T3=const wchar_t *,
1> T4=long,
1> T5=wxString
1> ]
1>Done building target "ClCompile" in project "wallet.vcxproj" -- FAILED.
1>
1>Done building project "wallet.vcxproj" -- FAILED.
1>
1>Build FAILED.

Further, the reason I wanted to turn off implicit conversion is because regardless of what locale is in effect, wxWidgets always defaults to ASCII, even though my execution environment and locale is UTF8, and when I use windows functions everything works:

Code: Select all

auto previous_locale =setlocale(LC_ALL, ".utf8");
wxLogMessage("previous Locale %s", previous_locale);
wxLocale TryingToGetUTF8;
auto success=TryingToGetUTF8.Init(wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT);
assert(success);
const char* test= "“quotes” camel’s Ellipses … ndash – mdash—separates smily : ☺ Sarcasm : 🙃";
wxString wxTest{ test};
wxString wxTestExplicitlyUTF8 = wxString::FromUTF8Unchecked(test);
wxLogMessage("testing set locale %s", test);
wxLogMessage("testing set locale %s", wxTest);
wxLogMessage("explicitly forcing utf8 %s", wxTestExplicitlyUTF8);
08:16:06: previous Locale English_Singapore.utf8
08:16:06: testing set locale “quotes” camel’s Ellipses … ndash – mdash—separates smily : ☺ Sarcasm : 🙃
08:16:06: testing set locale “quotes” camel’s Ellipses … ndash – mdash—separates smily : ☺ Sarcasm : 🙃
08:16:06: explicitly forcing utf8 “quotes” camel’s Ellipses … ndash – mdash—separates smily : ☺ Sarcasm : 🙃
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by ONEEYEMAN »

Hi,
Are you sure you compiled the library with UNICODE support? How did you build it - from the IDE or using the Command Prompt?
I.e., did you define "UNICODE" and "_UNICODE" when compiling?

Thank you.
Last edited by ONEEYEMAN on Tue May 11, 2021 11:21 pm, edited 1 time in total.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by stahta01 »

Are you using smart quotes where the compiler wants normal quotes?

Code: Select all

“quotes”
Edit: This is a wild guess on my part as a possible cause.

Tim S.
Cherry
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Apr 09, 2020 4:13 am

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by Cherry »

I think I have found the problem:

When I use wxLogMessage with a non wxString, it correctly throws the error, but the error message points at the wxWidgets headers, and fails to point at my error
Cherry
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Apr 09, 2020 4:13 am

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by Cherry »

When I test wxNO_IMPLICIT_WXSTRING_ENCODING with the sample "Minimal.cpp", it works

And when I deliberately make the error:

Code: Select all

wxLogMessage(_T("hail %s %s"), "John", "Doe");
It gives me the uninformative error message blaming wxWidgets instead of me.

Code: Select all

1>  minimal.cpp
1>  H:\wallet\wxWidgets\include\wx\log.h(984,1): error C2248: 'wxArgNormalizer<const char*>::get': cannot access private member declared in class 'wxArgNormalizer<const char*>'
1>  H:\wallet\wxWidgets\include\wx\strvararg.h(694): message : see declaration of 'wxArgNormalizer<const char*>::get'
1>  H:\wallet\wxWidgets\include\wx\strvararg.h(690): message : see declaration of 'wxArgNormalizer<const char*>'
1>  H:\wallet\wxWidgets\samples\minimal\minimal.cpp(130): message : see reference to function template instantiation 'void wxLogger::Log<const char*,const char*>(const wxFormatString &,T1,T2)' being compiled
1>          with
1>          [
1>              T1=const char *,
1>              T2=const char *
1>          ]
1>Done building target "ClCompile" in project "minimal.vcxproj" -- FAILED.
1>
Nah, wxWidgets is fine. Just my code has obvious errors, which are inevitably less obvious when visual studio blames some other file altogether.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING

Post by stahta01 »

Instead of

Code: Select all

wxLogMessage(_T("hail %s %s"), "John", "Doe");
Edit: Using "_T() in wxWidgets 3.1 and above is normally not needed and sometimes wrong"

Did you try

Code: Select all

wxLogMessage("hail %s %s", "John", "Doe");
Edit: I expect the above to fail.

and

Code: Select all

wxLogMessage(wxS("hail %s %s"), "John", "Doe");
Edit: I expect the above to wok.

Tim S.
Post Reply