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):
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 );
| ~~~~^~~~~
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:
--- 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)
I did not build wxWidgets. I use standard MinGW64 packages:
$ 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]
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.
I got the same error after this patch/change. Tim S.
Now researching the proper code fix.
Tim S.
Index: src/CodeBlocks_wx32_64.cbp
===================================================================
--- src/CodeBlocks_wx32_64.cbp (revision 13254)
+++ src/CodeBlocks_wx32_64.cbp (working copy)
@@ -649,7 +649,7 @@
<Add option="-DwxUSE_UNICODE" />
<Add option="-D_WIN64" />
<Add directory="$(#WX32_64.include)" />
- <Add directory="$(#WX32_64.lib)/gcc_dll$(WX_CFG)/msw$(WX_SUFFIX)" />
+ <Add directory="$(#WX32_64.lib)/wx/include/msw-unicode-3.2" />
<Add directory="sdk/wxscintilla/include" />
<Add directory="include/tinyxml" />
</Compiler>
I plan to add the patch files I am using to this post.
I also used the patch to src/sdk/projectloader.cpp that the OP posted. I forgot the wxcode stuff I knew it might be correct or it might not.
msys2_wx_CodeBlocks_wx32_64.cbp.patch contains a patch to modify CodeBlocks_wx32_64.cbp so it uses MSys2 MINGW64 wxwidgets 3.2 package.
MSys2 Packages that are likely needed; only tested using MINGW64 command window.
pacman -S --noconfirm --needed zip;
pacman -S --noconfirm --needed rsync;
pacman -S --noconfirm --needed subversion;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-gcc;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-cppcheck;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-boost;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-drmingw;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-wxwidgets3.2-msw;
pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-wxwidgets3.2-msw-cb_headers;
Commands used after CB core project CodeBlocks_wx32_64.cbp builds
./update 32_msys2
cd output32_msys2
./codeblocks.exe
Link to the normal build directions https://wiki.codeblocks.org/index.php/Installing_Code::Blocks_from_source_on_Windows (https://wiki.codeblocks.org/index.php/Installing_Code::Blocks_from_source_on_Windows)
Note: Those directions are not correct for use with these patch files; but, they might help. And, if you have never built CB the normal way it will be hard to build it this very unusual way.
Build finished;
Name : Code::Blocks
Version : svn-r13254
SDK Version : 2.24.0
Scintilla Version : 3.7.5
Author : The Code::Blocks Team
E-mail : info@codeblocks.org
Website : https://www.codeblocks.org
OS : Windows 10 (build 19045), 64-bit edition
Scaling factor : 1.250000
Detected scaling factor : 1.250000
Display PPI : 120x120
Display count : 2
Display 0 (\\.\DISPLAY1): XY=[0,0]; Size=[1280,1024]; Primary
Display 1 (\\.\DISPLAY2): XY=[1280,0]; Size=[1920,1080];
wxWidgets Library (wxMSW port)
Version 3.2.2 (Unicode: wchar_t, debug level: 1),
compiled at Mar 8 2023 20:18:16
Runtime version of toolkit used is 10.0.
Tim S.
For me, I think the code
glob.GetWildCard().mb_str()
will depends on the system's Local setting. For example, either in Chinese or other languages, the mb_str() will return different byte arrays. Is that correct?