Windows 10, VS Code with PlatformIO, compiling for ESP32
The source code is encoded with Windows-1252 as I use the ANSI character set of all 256 8 bit characters needed for a font to a TFT display. Using UTF-8 will corrupt the output totally.
In platformio.ini:
build_flags = -fexec-charset=windows-1252 -finput-charset=windows-1252
results in this error when compiling:
cc1plus.exe: error: no iconv implementation, cannot convert from windows-1252 to UTF-8
The iconv package: LibIconv for Windows
is installed and iconv.exe is in the path
What is missing here?
You need a version of gcc that is statically linked to libiconv. I’m not sure if PlatformIO ships such version.
Ok. Where is the setting for that in PlatformIO?
There is no such setting for PlatformIO.
The compiler is part of the platform and can’t be changed that easy.
I’m afraid you’re approaching the problem from the wrong side. You are trying to change the whole build system just to use a character set that is not supported by the compiler.
It is as if you had a car for left-hand traffic that you use in a country that has right-hand traffic and you now want to change the whole country to left-hand traffic. The correct solution would be to use a right-hand car.
In this example the unsupported character set is the car and the build environment / platform / compiler is the country.
Simply use hex notation for the special characters you want to use (as suggested in the other thread).
I understand that. It’s just so silly that a compiler should tell me what character encoding I must use. It should be the other way around!
There are a number of other solutions:
- Keep strings in UTF-8 and encode them to CP1252 whenever you send them to the TFT display. This incurs runtime costs and requires some encoding functions to be present.
- Keep strings intended for TFT display as byte arrays and not strings. To do that conversion, you can use
xxd
utility. It’s native for Linux, and you can use Windows version from Sourceforge, from WSL or from MSYS2, I think. Another utility (a number of utilities, actually) is called bin2c
. The downside is that the original text form of the strings will no longer be visible.
- Keep strings in separate files and embed them during the build. A StackOverflow answer outlines this approach: c++ - Embedding resources in executable using GCC - Stack Overflow. I haven’t tried this myself and I’m not sure how hard is it to automate if the string changes.
- Another solution also requires you to keep strings in separate files and uses some macro magic and assembler behind the scene: c++ - Embedding resources in executable using GCC - Stack Overflow. It’s called
incbin
library so you can “include” a file to the source code with macros. I’m not sure if it triggers the same warning from the compiler. Probably it won’t as the string becomes part of inline assembly and not C++ code.
1 Like
I completely understand all that. Yet I withstand with my very thoroughly thought through opinion that a compiler should never tell me what character encoding I must use. The compiler should obey my commands. Yet some crazy UTF-8 programmer decided that she knows best! OBEY she said and published the compiler!
That’s life. Unfortunately, it’s not always about what you want.
1 Like
Silly answer. As if your car had the steering wheel on the other side and the car dealer said “That’s life”
Because the issue is somewhere else: You bought the wrong car / or live in the wrong country. 
But I think the matter is clear:
- This isse is not about PlatformIO.
- There is nothing this community could do for your problem - except the solutions you already got from @azarubkin .
The encoding problem is perfectly solvable is the programmer can comprehend the fact that we’re not making programs to a huge IBM mainframe. We are dealing with microchips here! No MegaGiga bytes of memory here!
How hard can that be to understand?
You are asking at the wrong place! We cannot change the compiler etc…
Please contact the guys from GCC to support your desired encoding.
If there is a version, also contact Espressif to make use of this special GCC version.
Yes, the issue is absolutely in regard to PlatformIO.
PlatformIO is stalled in the choice of the compiler made for large computers. So stupid!
Even PlatformIO is the wrong place.
Try Espressif…
This is a community forum - driven by users to help users.