C++ Compiler Targets the Web

C++ Compiler Targets the Web

It is a common problem these days. You have a piece of code in C or C++. Maybe it is older code. Or maybe you prefer prototyping your ideas using C. But, inevitably, someone now wants your code to run in a Web browser. The options for making this happen have expanded quite a bit lately and one possibility is Cheerp, an open-source compiler that handles up to C++ 17 and can output to WebAssembly, JavaScript, or asm.js.


The compiler is free to use for GPLv2 projects. If you aren’t open yourself, it looks like you have to cut a deal to use Cheerp with its maker, Learning Technologies.

Traditionally, you’d use Emscripten to do something like this. According to the project’s site, Cheep generates faster and smaller WebAssembly than Emscripten and has several advantages if you compile to JavaScript. For example, they claim to have better dynamic memory handling, more efficient access to the DOM, and better JavaScript interoperability.


The Hello World example is, understandably, a little underwhelming, but does show some special features that allow direct access to the browser. They do point out that you can ignore that and use things like printf or court if you aren’t worried about performance. A better place to start if you want to do anything serious is the pong game example.


If you haven’t been keeping up with WebAssembly, we can get you started. If you don’t think any of this would have a ..

Support the originator by clicking the read the rest link below.