How not to do Unicode...
All started from a small problem, how to print Unicode text to the Windows Console with option redirect to a file.
Let's say we have a program Hello that prints few words in several languages to the screen..
#include <stdio.h>
int main()
{
printf("Мир Peace Ειρήνη\n");
return 0;
}
The program above is trivial and works fine under Windows if current console codepage is set to UTF-8. Also this can be fixed from the program by calling SetConsolseOutputCP(CP_UTF8).
Now simple tweak... Instead of that standard C printf we would use standard C++ std::cout... It works fine for GCC. But under Visual C++ it prints squares...
If I try redirection test.exe >test.txt - I get perfectly fine UTF-8 text...
I had started researching the issue and found the post of one of the Windows Unicode Gurus Michael Kaplan's.
I've tried to run _setmode(_fileno(stdout), _O_U8TEXT) as recommended by the
Microsoft's Unicode guru and... By program crashed on attempt to write
to the output stream.
Keeping searching for an answer I've got to this bug report...
Short summary:
- User: Can't print UTF-8 to console with std::cout
- MS: Closing - this is by design, see Michael Kaplan's article about writing to console
- User: But if I do what suggested program crashes, and I still can't write Unicode to console
- MS: Reactivate the ticket if it does not works
- User: it does not!
- MS: Use wide output...
- User: I'd rather use fprintf in first place!?
To the summary...
If you use Visual C++ you can't use UTF-8 to print text to std::cout.
If you still want to, please read this amazingly long article about
how to make wcout and cout working, but it does not really give a simple
solution - finally falling to redefinition of the stream buffers...
So please, if you design API or Operating System, do not use kind of "Wide" API... This is is the wrong way to do Unicode.
Which reminds me... Spread around:
http://www.utf8everywhere.org/
Related Posts: http://blog.cppcms.com/post/62
RPM Repositories for CppCMS
Additionally to DEB Repositories, RPM repositories are ready as well.
The packages are build using Open Build Service:
- Distributions: Fedora 15 and 16, CentOS 6, OpenSuse 11.4 and 12.1
- Architectures: x86, x86_64
- Packages: libcppcms, libcppcms-devel, cppcms-tools
- Sources: cppcms
http://download.opensuse.org/repositories/home:/artyom-beilis/
CppCMS 1.0.1 - Bug Fix Release
CppCMS 1.0.1 Released
It is a bug fix release:
- Fixed crash when using process-shared memory cache, when CppCMS compiled in Release mode with gcc 4.5 and 4.6.
- Added support of CMake LIBDIR option to allow installation of libraries to lib64 instead of lib as required by Rad Had based distributions.
Additionally to the deb releases, now source-rpm is available at sourceforge.
In order to create RPMs for your system:
Install dependent packages:
yum install cmake gcc-c++ gcc make zlib-devel pcre-devel libicu-devel libgcrypt-devel
Download source rpm and rebuild it as:
rpmbuild --rebuild cppcms-1.0.1-1.src.rpm
You will get 3 binary rpm packages: libcppcms, libcppcms-devel and cppcms-tools in the ~/rpmbuild/RPMS/ directory. Install them and use them.
Special Thanks: to Sagi Ben-Akiva for initial spec file that made this process much simpler for me.
CppCMS 1.0.0 released and offered under dual license
CppCMS 1.0.0 was released today. Now it is offered under alternative commercial license. You can choose to use CppCMS under either open source LGPLv3 license or under a commercial license that allows your developing truly closed source applications.
For more details about licensing and pricing please visit
our web site:
http://commercial.cppcms.com
The old-stable branch of CppCMS - 0.0.x is now deprecated and would not receive any updates. CppCMS users who still use CppCMS 0.0.8 are encouraged to upgrade to the CppCMS 1.
The new version includes:
- Stable API and ABI
- Comet and Ajax support
- Powerful localization
- Native Windows support
- And much more
You can find more details about the differences between CppCMS 1.0.0 and CppCMS 0.0.8 here
Apt Repositories
New Apt repositories for Debian and Ubuntu are available.

