emscripten - 断言失败:在 .js 文件 (emscripten) 中调用 c 函数时,在运行时初始化错误之前调用了本机函数 `int_sqrt`
问题描述
我无法在另一个 JavaScript 文件中调用 C 函数,它给出了错误“在运行时初始化之前调用” 请参阅此链接
我按照给定链接中的描述在 emscripten 中编译了 C 代码,并在我的 test.js 文件中使用了生成的 asm.js 文件。用于生成 asm 的命令:-
emcc test/hello.cpp -o hello.html -s EXPORTED_FUNCTIONS="['_int_sqrt']" -s EXPORTED_RUNTIME_METHODS="["ccall", "cwrap"]"
test.js 文件中的代码:
var Module = require('./asm.js');
var test = Module.cwrap('int_sqrt', 'number', ['number']);
console.log(test(25));
当我运行时node test
它给出了错误
abort(Assertion failed: native function `int_sqrt` called before runtime initialization)
解决方案
你应该等待运行时初始化。
尝试这个:
var Module = require("./lib.js");
var result = Module.onRuntimeInitialized = () => {
Module.ccall('myFunction', // name of C function
null, // return type
null, // argument types
null // arguments
);
}
推荐阅读
- vue.js - 未捕获的类型错误:无法读取未定义 vue 的属性“位置”
- polygon - 使用带有 geotools 24.0 的形状文件数据存储加载多边形几何时出错
- pyinstaller - 是否有等效于使用 PyObjC 的“os.listdir()”方法?
- google-chrome - 如何从弹出窗口访问当前选项卡的 LocalStorage 和 Cookie
- android - Bitbucket Container 'Build' 超出内存限制 - 使用 android build 时
- kotlin - 如何测试返回 com.google.type.Money 的 gRPC 端点
- android - 我无法读取我的 FirebaseDatabase。它显示警告为:W/System: Ignoring header X-Firebase-Locale because its value is null
- python - 将具有不同形状的numpy数组列表转换为灰度值
- javascript - 我的三元代码不起作用 Javascript
- python - 如何将 python 列表中的每个元素与另一个列表中的元素相乘?