Monday, December 23, 2013

Emscripten

Could I possibly get The Little Crane That Could to run in a browser window? If a modest Raspberry Pi can run it, why not a 'lowly' browser?

Inspired by a blog posting from Dirk Krause over at web3dblog, I decided to look into this. And my weapon of choice: emscripten, because I grow fonder of the C programming language each year, and have no appetite for Javascript. Hurdle number one is the outdated build instructions on linux that I found here. So in this blog posting I will document the attempt to emscripten my game.

  • Instead of building llvm/clang from source, I simply install those from the ubuntu repository using 'apt-get install clang-3.2'.
  • It turned out that emcc cannot find llvm-link on my system. This is because ubuntu installs it as llvm-link-3.2 so this needs fixing.
  • Like clang and llvm, node.js can also be obtained from Ubuntu's repository using the 'apt-get install nodejs' command.
  • With those modifications, the compiler seems to work just fine.
    $ nodejs a.out.js
    hello, world!
    
  • To target ASM.JS you can use this command line:
    $ ./emcc -O1 -s ASM_JS=1 tests/hello_world.c
  • There is an emar archiver tool, but combining bytecode objects into an archive gives unresolved symbols when I link against this archive. fixed by using -L. flag.
  • You can put files onto a virtual file system using the --embed-file compiler flag. I've not yet figured out how to successfully use dlopen() though.

Lastly, these slides on an emscripten talk are very interesting.

No comments:

Post a Comment