簡體   English   中英

斷言失敗:在調用 c function in.js 文件 (emscripten) 時,在運行時初始化錯誤之前調用了本機 function `int_sqrt`

[英]Assertion failed: native function `int_sqrt` called before runtime initialization error while calling c function in .js file ( emscripten )

我無法在另一個 JavaScript 文件中調用 C function,它給出錯誤“在運行時初始化之前調用”, 請參閱此鏈接

我按照給定鏈接中的描述在 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
   );
}

我在使用emscripten時遇到了同樣的問題,這對我有用:

<script>
    Module.onRuntimeInitialized = () => { Module.functionName(param); }
</script>

其中functionName是您要調用的 function 的名稱, param是您要傳遞給它的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM