Non-Unicode/MBCS wxWidgets build for Visual Studio [How we solved it]

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
gasko
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Apr 13, 2020 11:14 am

Non-Unicode/MBCS wxWidgets build for Visual Studio [How we solved it]

Post by gasko » Mon Apr 13, 2020 11:36 am

Hi all

We have a large legacy project which uses "Multi-Byte Character Set" i.e. ANSI char options instead of Unicode and therefore needed to build wxWidgets for MBCS as well.

There were lots of issues in doing this, such as the following linker error:
- unresolved external symbol wxAppConsoleBase::OnAssert

This is how we built non-Unicode wxWidgets successfully for Visual Studio 2019 on Windows 10:
1. Download and install wxWidgets and open the installation folder (named WXWIN from now on)
2. Go to WXWIN\include\wx\msw\setup.h and change "wxUSE_UNICODE 1" to "wxUSE_UNICODE 0"
3. Go to WXWIN\build\msw and open wx_vc16.sln (or the version of your choice)
4. BEFORE batch building, highlight all projects in the solution > right-click > properties > Configuration Properties > Advanced and set "Character Set" to "Use Multi-Byte Character Set" for ALL CONFIGURATIONS
5. Then go to C/C++ > Preprocessor > Preprocessor Definitions for EACH project and remove "_UNICODE" manually for ALL CONFIGURATIONS. Not all of the projects have this define set so you may have to select them in small groups or do them individually to ensure you remove it for all.
6. You can then batch build as normal: go to Build > Batch Build and then "Select All" and then "Build"
7. When you include wxWidgets, ensure your project is also set to non-Unicode

Step 5 was the route of our problems. Even though we defined wxUSE_UNICODE 0, it seems this macro merely changes the "overall" configuration for wxWidgets, and not the configuration for each sub-project/library. Further, the _UNICODE define seemingly overrode this option anyway, as visible in the code under "platform.h" which switches BOTH wxUSE_UNICODE and _UNICODE on if EITHER option is on.

Hope this helps someone!

Regards,
Gary

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2355
Joined: Sun Jan 03, 2010 5:45 pm

Re: Non-Unicode/MBCS wxWidgets build for Visual Studio [How we solved it]

Post by PB » Mon Apr 13, 2020 1:44 pm

Thanks for the info.

If one is not afraid of using command line, MBCS version of wxWidgets can be easily built with nmake like this

Code: Select all

nmake -f makefile.vc UNICODE=0 CPPFLAGS="/D_MBCS"
I assume it would be similarly easy to generate MSVS projects with bundled CMakeFile: just check off wxUSE_UNICODE, define _MBCS, generate the project, build the project in MSVS.

BTW, I am not sure about your formulation "Multi-Byte Character Set" i.e. ANSI char options". I believe that Unicode, ANSI, and MBCS are three different character encodings in MSVC:
  1. ANSI: the original C encoding, every character is exactly one byte, neither _MBCS nor _UNICODE is defined, the string comparison function would be strcmp(). This was the default wxWidgets encoding until wxWidgets 2.9.
  2. Unicode: characters are wchar_t-based (UTF-16 strings), _UNICODE is defined, the string comparison function would be wcscmp(). This is the default wxWidgets encoding since wxWidgets 2.9.
  3. MBCS: was usually used with CJK languages, characters are 1 or 2 bytes long (MSVC supports only DBCS), _MBCS is defined, the string comparison function would be _mbscmp().

Post Reply