- Hands-On Game Development with WebAssembly
- Rick Battagline
- 493字
- 2021-06-24 13:41:01
Using Emscripten
We run Emscripten from the command line; therefore, you can use any text editor you choose to write your C/C++ code. Personally, I am partial to Visual Studio Code, which you can download here: https://code.visualstudio.com/download.
One beautiful thing about Visual Studio Code is that it has a built-in command-line terminal, which lets you compile your code without switching windows. It also has an excellent C/C++ extension that you can install. Just search for C/C++ from the extensions menu and install the Microsoft C/C++ Intellisense extension.
Whatever you choose for your text editor or integrated development environment, you need a simple piece of C code to test out the emcc compiler.
- Create a new text file and name it hello.c.
- Type the following code into hello.c:
#include <emscripten.h> #include <stdlib.h>
#include <stdio.h>
int main() { printf("hello wasm\n"); }
- Now I can compile the hello.c file into WebAssembly and generate a hello.html file:
emcc hello.c --emrun -o hello.html
- The --emrun flag is necessary if you want to run the HTML page from emrun. This flag adds code that will capture stdout, stderr, and exit in the C code and emrun will not work without it:
emrun --browser firefox hello.html
Running emrun with the --browser flag will pick the browser where you would like to run the script. The behavior of emrun seems to be different between browsers. Chrome will close the window when the C program exits. That can be annoying because we are just trying to display a simple print message. If you have Firefox, I would suggest running emrun using the --browser flag.
To find out what browsers are available to you, run the following:
emrun --list_browsers
emrun should open an Emscripten-templated HTML file in a browser.
Make sure you have a browser capable of running WebAssembly. The following versions of the major browsers should work with WebAssembly:
- Edge 16
- Firefox 52
- Chrome 57
- Safari 11
- Opera 44
- Intel FPGA/CPLD設計(基礎篇)
- Learning AngularJS Animations
- 新型電腦主板關鍵電路維修圖冊
- 電腦軟硬件維修大全(實例精華版)
- Linux運維之道(第2版)
- 現代辦公設備使用與維護
- 硬件產品經理手冊:手把手構建智能硬件產品
- Manage Partitions with GParted How-to
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- 從零開始學51單片機C語言
- STM32嵌入式技術應用開發全案例實踐
- OpenGL Game Development By Example
- Blender Quick Start Guide
- Neural Network Programming with Java(Second Edition)
- 無蘋果不生活:OS X Mountain Lion 隨身寶典