WebAssembly LinkError when I use "printf" function in my cpp.

Error String: Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #2 module="env" function="_printf" error: function import requires a callable
Here is my source

#include <stdio.h>
extern "C" int test()
{
    printf("OK");
    return 0;
}
loadWebAssembly("main.wasm").then(instance => {
                instance.exports._test();
            });

when I set a importObjects like this, but console allways log '0'.

    var imports = {
        env: {
            _printf: msg => console.log(msg)
        }
    };

I'm not find the relationship of var type between 'js' and 'cpp' in emscripten, what should i do, how to link to WebGL2(unusefull when I add "-s USE_WEBGL2=1"), thinks!

阅读 2.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题