emscripten asm.js的helloworld

加压emsdk-portable.tar.gz

./emsdk install latest
./emsdk activate latest
source emsdk_env.sh

参考
中文
http://www.ruanyifeng.com/blog/2017/09/asmjs_emscripten.html
英文
https://kripken.github.io/mloc_emscripten_talk/cppcon.html#/
faq
http://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html

#include <emscripten.h>

extern "C" {
  double SquareVal(double val) {
    return val * val;
  }
}

int main() {
  EM_ASM({
    SquareVal = Module.cwrap('SquareVal', 'number', ['number']);
    var x = 12.5;
    alert('Computing: ' + x + ' * ' + x + ' = ' + SquareVal(x));
  });
}



emcc -s EXPORTED_FUNCTIONS="['_SquareVal', '_main']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']"  example4.cc -o example4.html

生成example4.js 和example4.html
python -m SimpleHTTPServer 8080

猜你喜欢

转载自haoningabc.iteye.com/blog/2411956
今日推荐