even though wasi-sdk-33 mentions
Build a sysroot that supports C++ exceptions by default
i was unable to compile c++ that uses exceptions to wasm
source file
__attribute__((import_module("env"), import_name("print")))
extern void print(const char*);
struct base {
virtual void method() noexcept(false) = 0;
};
struct foo : base {
void method() override {
print("foo");
}
};
struct bar : base {
void method() override {
print("bar");
}
};
void destruct(base* object) {
try {
object->method();
} catch (...) {
print("error");
}
}
clang output
vm@Comp:~$ ./wasi-sdk-33.0-x86_64-linux/bin/clang -xc++ -std=c++23 --target=wasm32-wasip1 -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind -Wl,--export-all -o test.wasm test.cpp
wasm-ld: error: /home/vm/wasi-sdk-33.0-x86_64-linux/bin/../share/wasi-sysroot/lib/wasm32-wasip1/eh/libunwind.a(Unwind-wasm.c.o): undefined symbol: __gxx_personality_wasm0
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_begin_catch
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: print(char const*)
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_end_catch
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_end_catch
clang: error: linker command failed with exit code 1 (use -v to see invocation)
even though wasi-sdk-33 mentions
i was unable to compile c++ that uses exceptions to wasm
source file
clang output