emcc命令

emcc D:\cppcode\AutoFollow\hello1.cpp -s WASM=1 -o D:\cppcode\AutoFollow\hello\hello2.js

c++代码

#include <stdio.h>
#include <emscripten/emscripten.h>
extern "C"
{
  int EMSCRIPTEN_KEEPALIVE aa(int x)
  {
    if (x <= 0)
      return 0;
    if (x <= 2)
      return 1;
    return x - 2;
  }
  int EMSCRIPTEN_KEEPALIVE  my_function(int a, int b)
  {
    return a + b;
  }
}

前端代码(vue框架)

loadWasm2() {
      this.fetchAndInstantiate(this.$JBolt.API.cems_bigdata.server.downloadFile, this.importObject).then(function(instance) {
        console.warn(instance.exports.aa(100));
      });
      
    },
    fetchAndInstantiate(url, importObject) {
      return fetch(url, {
        method: "post",
        body: JSON.stringify({ }),
        headers: {
         	//根据项目来
        }
      }).then(response =>
        response.arrayBuffer()
      ).then(bytes =>
        WebAssembly.instantiate(bytes, importObject)
      ).then(results =>
        results.instance
      );
    },
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐