【发布时间】:2018-11-14 21:37:22
【问题描述】:
我正在尝试将使用 emscripten 生成的模块导入为 es6 模块。 我正在尝试使用来自 emscripten doc 的 basic example。
这是我用来从 C 模块生成 js 模块的命令:
emcc example.cpp -o example.js -s EXPORTED_FUNCTIONS="['_int_sqrt']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap']" -s EXPORT_ES6=1 -s MODULARIZE=1
C 模块:
#include <math.h>
extern "C" {
int int_sqrt(int x) {
return sqrt(x);
}
}
然后导入生成的js模块:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Wasm example</title>
</head>
<body>
<script type="module">
import Module from './example.js'
int_sqrt = Module.cwrap('int_sqrt', 'number', ['number']);
console.log(int_sqrt(64));
</script>
</body>
</html>
这是失败的,因为模块对象上没有 cwrap:
Uncaught TypeError: Module.cwrap is not a function
【问题讨论】:
标签: javascript es6-modules emscripten webassembly