我正在尝试构建使用 JS 对象引用(类型为
emscripten::val
或 emscripten::EM_VAL
)的简单 WebAssembly 应用程序。
代码:
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
extern "C"
{
EMSCRIPTEN_KEEPALIVE void Draw(emscripten::val canvas)
{
emscripten::val::global("console").call<void>("log", canvas);
}
}
我尝试使用
emcc
(根据指令安装)、Emscripten CMake工具链和Blazor WebAssembly(C#/.NET,指令)构建仅包含上述代码的项目。无论尝试将 C++ 代码编译为 wasm 的方式如何,我都会在输出中看到相同的多个错误:
NativeClient_0.o: undefined symbol: _emval_get_global
NativeClient_0.o: undefined symbol: _emval_decref
NativeClient_0.o: undefined symbol: _emval_call_void_method
NativeClient_0.o: undefined symbol: _emval_get_method_caller
NativeClient_0.o: undefined symbol: _emval_incref
对 emcc 和 em++ 编译器使用
--bind
,如果使用则删除 -s WASM=1
。