Eliminates the need for WebAssembly asm js

Use Boost with Emscripten - Javascript, C ++, Boost, Emscripten

I have a C ++ project that I want to convert into a web application. For this purpose I would like to use Emscripts to create the project.

The project uses some external libraries. I've managed to compile or find the JavaScript version of most of the libraries and now I'm standing by the Boost libraries. Actually, I don't even know how to start with Boost: you're using a Boostrap script to generate the files to build the libraries. It is possible to pass the toolset to this script, but emscripting is obviously not supported.

My project uses the following parts of Boost: thread, regex, filesystem, signals, system. How can I compile these libraries with Emscripts?

To edit

After npclaudiu's answer, I booted the library using the gcc toolkit and then edited it to configure the compiler, replace:


Typing now effectively builds the libraries. Boost.Signals and Boost.System compile well. The others have some flaws.

Boost.Thread complains:

Boost.Regex complains a lot about CHAR_BIT not to be declared, but it seems to be a problem in emscripts:

Boost.FileSystem also seems to fail on emscripts:


21 for the answer № 1

I finally managed to compile the required libraries with emscripten. Here are the steps I followed.

Edit to add the following definitions (see http://github.com/kripken/emscripten/issues/531):

Add the following line

As suggested by npclaudiu, bootstrap the library using the gcc toolkit. Then edit to configure and replace the compiler:


Makes me around the line 67.

Then compile the libraries:

Do all of the above, then edit and replace:




Compile the libraries:

5 for the answer № 2

Boost now includes an "emscripted" toolset for recording, which (in my experience) makes the process described above superfluous.

Use Boostrap-Boost as usual and then compile with b2 (or bjam) as follows:

2 for the answer № 3

You can try to configure Boost libraries with the appropriate settings as a toolset, as recommended by Emscripten as a drop-in replacement for GCC. I also think it's better if you build Boost than static libraries for this case. Remember that most Boost libraries are just headers as they only define classes and functions for templates.

1 for the answer № 4

I don't know if you have that specific question in the FAQ, but if you don't:

Q. How can I link to system libraries like SDL, Boost etc?

A. System libraries that are contained in emscripten - libc, libc ++ (C ++ STL) and SDL - are automatically included during compilation (and only the necessary parts of them). You don't even need -lSDL, unlike other compilers (but -lSDL doesn't hurt either).

Other libraries that are not included in emscripten like boost, You would have to compile yourself and link it to your program as if they were a module in your project. For example like banana bread links in libz. (Note that in the special case of Boost, you don't need anything if you just need the Boost headers.)

Another option for libraries that are not included is to implement it as a JS library, as is the case with emscripten for libc (minus malloc) and SDL (but not libc ++ or malloc). See --js-library in emcc.