起因
最近在学习WebAssembly这一门语言,尝试将C/C++的源码通过Emscripten
或者wasicc
编译成WebAssembly二进制文件。
然而虽然WebAssembly语言是支持异常处理的,但是无论是Emscripten
还是wasicc
目前都是不支持将C++的exception编译为WebAssembly,会报错。例如使用wasic++
编译一个包含有throw
…catch
…等关键字的程序,就会出现以下错误:
wasm-ld: error: /tmp/correlation-bc333a.o: undefined symbol: __cxa_allocate_exception
wasm-ld: error: /tmp/correlation-bc333a.o: undefined symbol: __cxa_throw
wasm-ld: error: /tmp/correlation-bc333a.o: undefined symbol: __cxa_allocate_exception
wasm-ld: error: /tmp/correlation-bc333a.o: undefined symbol: __cxa_throw
然后如果我再编译时使用禁用exception的选项,也即-fno-exceptions
,由于源代码中还是有throw
…catch
…等关键字,编译报错为: