【发布时间】:2017-07-23 02:12:29
【问题描述】:
在 JS 中从 Emscripten 编译的 WASM 创建 WebAssembly.Instance,其中包括对 sprintf 的调用,会导致此错误:
Uncaught (in promise) LinkError: WebAssembly.Instance(): Import #1 module="env" function="_sprintf" error: function import requires a callable...
sprintf 不是 included by Emscripten 作为 libc 的一部分吗?
代码:
#include <stdio.h>
extern "C" {
int main() {
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
return 0;
}
}
编译命令:
emcc src/test.cpp -O3 -s WASM=1 -s SIDE_MODULE=1 -o out/test.wasm
emcc 编译运行没有错误。
注释掉 sprintf 行运行没有错误,按预期返回 0。
出现此错误的原因是什么,使用 sprintf 时如何避免?
【问题讨论】:
标签: emscripten webassembly emcc