Getting started

To get started with Cheerp, you’ll first need to install it.

Cheerp in itself has no dependencies, but the recommended workflow and the tutorials make use of:

  • a JavaScript engine (such as Node.js)
  • an HTTP server (such as http-server)
  • a web browser

If you don’t have these, see recommended workflow.

Compiling your first application

You are now ready for compiling your first Web application using Cheerp. Move to a folder of your choice and save the following C++ program as hello.cpp.

// The cheerp/clientlib.h header contains declarations for the browser APIs
#include <cheerp/clientlib.h>
// webMain is the entry point for web applications written in Cheerp
void webMain()
client::console.log("Hello, World Wide Web!");

You can then compile this program using the following command line:

Terminal window
/opt/cheerp/bin/clang++ -target cheerp hello.cpp -o hello.js

Great, you have compiled your first program with Cheerp. You can now run the generated JavaScript directly with

Terminal window
node hello.js

You can also save this HTML file as hello.html:

<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<title>Cheerp example 0: hello</title>
<script defer src="hello.js"></script>
<h1 id="pagetitle">
Open the console log (Ctrl + Shift + J or Ctrl + Option + J) to read the

and from the same folder firefox hello.html (or equivalent).

This is what the result should look like: hello.html

Why webMain() instead of main()?

What is console.log()?

It would have compiled also with std::cout<< , printf() or int main() (try it yourself), but we wanted to show first what zero-overhead access to the browser looks like.

Was this page helpful?
Suggest changes