Tuesday, December 20, 2011

New Emscripten tutorial: C/C++ to JavaScript now easier than ever with "emcc"

A new compiler frontend for Emscripten, emcc, has landed recently. emcc can be used basically as a drop-in replacement for gcc, making it much easier to compile C and C++ into JavaScript. For example,

   emcc src.cpp

will generate a.out.js, and

  emcc src.cpp -o src.html

will generate a complete HTML file with the compiled code as embedded JavaScript, including SDL support so the code can render to a Canvas element. Optimizing code is now easy as well,

  emcc -O2 src.cpp

will generate optimized code (optimizing in LLVM, the Emscripten compiler itself, the Closure Compiler, and the Emscripten JavaScript optimizer). (Note that there is an even faster setting, -O3, see the docs for more.)

emcc is presented in more detail in the new Emscripten Tutorial. Check it out! Feedback is welcome :)


  1. Great! I'll give it a spin tomorrow

  2. This comment has been removed by the author.

  3. Does emmaken.py still relevent ?

    Can you explain what appends when using emcc this way:

    emcc src1.cpp src2.cpp

    Do you use llvm-link to link LLVM bytecode files ?


  4. Edwin: emmaken still works, but is deprecated, and not tested so it might break eventually. emcc does everything it can, and more, so it's strongly recommended.

    emcc src1.cpp src2.cpp will combine those files into one final JavaScript file, just like gcc would. You don't need to run llvm-link in this case.

  5. Hi,

    If one day you are looking for another challenging mission in the javascript world please let me know. I am looking for someone that could help us to improve an objective-J(see cappuccino web framework) parser.
    More info here : https://groups.google.com/group/objectivej/browse_thread/thread/750257682bccd22d?hl=en&pli=1