User forums > General (but related to Code::Blocks)
Implicit wxString to char* conversion in src/sdk/projectloader.cpp
jdx:
For the first time in my life I am trying to build C::B. My setup is Windows 10, current MSYS2/MinGW (including wxWidgets 3.2.2.1) and current nightly C::B build. I started C::B, opened CodeBlocks_wx32_64.cbp (BTW. info in <CB_ROOT>\BUILD is outdated), modified wxWidgets include paths and after some time I got the following strange error(s):
--- Code: ---g++.exe -Wall -std=gnu++11 -m64 -g -pipe -mthreads -fmessage-length=0 -fexceptions -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DCB_PRECOMP -DwxUSE_UNICODE -D_WIN64 -Woverloaded-virtual -DEXPORT_LIB -DEXPORT_EVENTS -DWXMAKINGDLL_SCI -iquote.objs32_64\include -I.objs32_64\include -I. -IC:\Tools\MSYS\mingw64\include\wx-3.2 -IC:\Tools\MSYS\mingw64\lib\wx\include\msw-unicode-3.2 -Isdk\wxscintilla\include -Iinclude\tinyxml -Iinclude -Iinclude\tinyxml -Iinclude\scripting\include -Isdk\mozilla_chardet\include -Isdk\mozilla_chardet\include\mfbt -Isdk\mozilla_chardet\include\nsprpub\pr\include -Isdk\mozilla_chardet\include\xpcom -Isdk\mozilla_chardet\include\xpcom\base -Isdk\mozilla_chardet\include\xpcom\glue -Isdk\scripting\bindings -c D:\Works\CodeBlocks\src\sdk\projectloader.cpp -o .objs32_64\sdk\projectloader.o
D:\Works\CodeBlocks\src\sdk\projectloader.cpp: In member function 'bool ProjectLoader::ExportTargetAsProject(const wxString&, const wxString&, TiXmlElement*)':
D:\Works\CodeBlocks\src\sdk\projectloader.cpp:1776:30: error: no matching function for call to 'TiXmlElement::SetAttribute(const char [9], wxString)'
1776 | element->SetAttribute("wildcard", glob.GetWildCard());
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from D:\Works\CodeBlocks\src\include\configmanager.h:15,
from D:\Works\CodeBlocks\src\include\sdk_common.h:121,
from D:\Works\CodeBlocks\src\include\sdk_precomp.h:13:
include\tinyxml/tinyxml.h:1062:14: note: candidate: 'void TiXmlElement::SetAttribute(const char*, const char*)'
1062 | void SetAttribute( const char* name, const char * _value );
| ^~~~~~~~~~~~
include\tinyxml/tinyxml.h:1062:59: note: no known conversion for argument 2 from 'wxString' to 'const char*'
1062 | void SetAttribute( const char* name, const char * _value );
| ~~~~~~~~~~~~~^~~~~~
include\tinyxml/tinyxml.h:1082:14: note: candidate: 'void TiXmlElement::SetAttribute(const char*, int)'
1082 | void SetAttribute( const char * name, int value );
| ^~~~~~~~~~~~
include\tinyxml/tinyxml.h:1082:51: note: no known conversion for argument 2 from 'wxString' to 'int'
1082 | void SetAttribute( const char * name, int value );
| ~~~~^~~~~
D:\Works\CodeBlocks\src\sdk\projectloader.cpp:1778:30: error: no matching function for call to 'TiXmlElement::SetAttribute(const char [3], wxString)'
1778 | element->SetAttribute("id", wxString::Format("%lld", glob.GetId()));
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include\tinyxml/tinyxml.h:1062:14: note: candidate: 'void TiXmlElement::SetAttribute(const char*, const char*)'
1062 | void SetAttribute( const char* name, const char * _value );
| ^~~~~~~~~~~~
include\tinyxml/tinyxml.h:1062:59: note: no known conversion for argument 2 from 'wxString' to 'const char*'
1062 | void SetAttribute( const char* name, const char * _value );
| ~~~~~~~~~~~~~^~~~~~
include\tinyxml/tinyxml.h:1082:14: note: candidate: 'void TiXmlElement::SetAttribute(const char*, int)'
1082 | void SetAttribute( const char * name, int value );
| ^~~~~~~~~~~~
include\tinyxml/tinyxml.h:1082:51: note: no known conversion for argument 2 from 'wxString' to 'int'
1082 | void SetAttribute( const char * name, int value );
| ~~~~^~~~~
--- End code ---
The error is "strange" because it is so obvious that I am wondering why it is still there. It looks like the author(s) must have relied on some implicit wxString -> char* conversion. Anyway, mb_str() seems to solve the issue:
--- Code: ------ src/sdk/projectloader.cpp (revision 13254)
+++ src/sdk/projectloader.cpp (working copy)
@@ -1773,9 +1773,9 @@
for (const ProjectGlob& glob : m_pProject->GetGlobs())
{
TiXmlElement *element = AddElement(prjnode, "UnitsGlob", "directory", glob.GetPath());
- element->SetAttribute("wildcard", glob.GetWildCard());
+ element->SetAttribute("wildcard", glob.GetWildCard().mb_str());
element->SetAttribute("recursive", glob.GetRecursive() ? 1 : 0);
- element->SetAttribute("id", wxString::Format("%lld", glob.GetId()));
+ element->SetAttribute("id", wxString::Format("%lld", glob.GetId()).mb_str());
element->SetAttribute("addToProject", glob.GetAddToProject() ? 1 : 0);
const wxArrayString targets = glob.GetTargets();
if (targets.size() > 0)
--- End code ---
PB:
--- Quote from: jdx on April 09, 2023, 02:22:49 pm ---It looks like the author(s) must have relied on some implicit wxString -> char* conversion.
--- End quote ---
For better or worse, wxString is convertable to char* by default, see https://docs.wxwidgets.org/stable/overview_string.html#overview_string_implicitconv
Perhaps you built wxWidgets with wxUSE_UNSAFE_WXSTRING_CONV defined to 0?
jdx:
I did not build wxWidgets. I use standard MinGW64 packages:
--- Code: ---$ pacman -Ss wxwidgets|grep mingw64
mingw64/mingw-w64-x86_64-wxPython 4.2.0-1
mingw64/mingw-w64-x86_64-wxPython4.0 4.0.7.2-4
mingw64/mingw-w64-x86_64-wxwidgets3.0-msw 3.0.5.1-16
mingw64/mingw-w64-x86_64-wxwidgets3.0-msw-libs 3.0.5.1-16
mingw64/mingw-w64-x86_64-wxwidgets3.1-msw 3.1.7-6
mingw64/mingw-w64-x86_64-wxwidgets3.1-msw-libs 3.1.7-6
mingw64/mingw-w64-x86_64-wxwidgets3.2-common 3.2.2.1-2 [installed]
mingw64/mingw-w64-x86_64-wxwidgets3.2-common-libs 3.2.2.1-2 [installed]
mingw64/mingw-w64-x86_64-wxwidgets3.2-gtk3 3.2.2.1-2
mingw64/mingw-w64-x86_64-wxwidgets3.2-gtk3-libs 3.2.2.1-2
mingw64/mingw-w64-x86_64-wxwidgets3.2-msw 3.2.2.1-2 [installed]
mingw64/mingw-w64-x86_64-wxwidgets3.2-msw-cb_headers 3.2.2.1-2 [installed]
mingw64/mingw-w64-x86_64-wxwidgets3.2-msw-libs 3.2.2.1-2 [installed]
--- End code ---
Also I did not modify preprocessor defines in C::B project settings, only search paths and library names (MinGW64 does not use monolithic wxWidgets). Either way, relying on implicit conversion is rather bad practice.
stahta01:
How did you try to build Code::Blocks?
Using CB and CB Projects?
Or configure/make?
Or other method?
I have not tried to build C::B for about an year; and, I forget if the build had error or not.
Tim S.
jdx:
--- Quote from: stahta01 on April 10, 2023, 01:56:05 pm ---How did you try to build Code::Blocks?
Using CB and CB Projects?
--- End quote ---
Yes.
--- Quote from: stahta01 on April 10, 2023, 01:56:05 pm ---Or other method?
--- End quote ---
Is there another method? I'm dreaming of cmake.
Navigation
[0] Message Index
[#] Next page
Go to full version