Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
-
- Earned a small fee
- Posts: 10
- Joined: Fri Dec 06, 2019 1:10 pm
Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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.
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.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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
Tim 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.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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
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
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
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.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
You typo-ed the name of the define "wxNO_IMPLICIT_WXSTRING_ENCODING" Has WXSTRING in it; not WSTRING!
Tim S.
Tim S.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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.
You are supposed to according to the directions define it when building your application! Not while building the library.
Tim S.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
Still fails if I define it in my application instead of setup.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:
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 :
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>
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: 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 :
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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.
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.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
Are you using smart quotes where the compiler wants normal quotes?
Edit: This is a wild guess on my part as a possible cause.
Tim S.
Code: Select all
“quotes”
Tim S.
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
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
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
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
When I test wxNO_IMPLICIT_WXSTRING_ENCODING with the sample "Minimal.cpp", it works
And when I deliberately make the error:
It gives me the uninformative error message blaming wxWidgets instead of me.
Nah, wxWidgets is fine. Just my code has obvious errors, which are inevitably less obvious when visual studio blames some other file altogether.
And when I deliberately make the error:
Code: Select all
wxLogMessage(_T("hail %s %s"), "John", "Doe");
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>
Re: Question when compiling with wxNO_IMPLICIT_WXSTRING_ENCODING
Instead of
Edit: Using "_T() in wxWidgets 3.1 and above is normally not needed and sometimes wrong"
Did you try
Edit: I expect the above to fail.
and
Edit: I expect the above to wok.
Tim S.
Code: Select all
wxLogMessage(_T("hail %s %s"), "John", "Doe");
Did you try
Code: Select all
wxLogMessage("hail %s %s", "John", "Doe");
and
Code: Select all
wxLogMessage(wxS("hail %s %s"), "John", "Doe");
Tim S.