How to export function?
tagcode opened this issue · comments
tagcode commented
[DllImport] imports a function from another .wasm binary, but how to export one?
wasm-objdump reveals only "_start."
wasm-objdump -x -j export ConsoleApp11.wasm
ConsoleApp11.wasm: file format wasm 0x1
Section Details:
Export[6]:
- memory[0] -> "memory"
- func[24] <_start> -> "_start"
- func[7565] <free> -> "free"
- func[7563] <malloc> -> "malloc"
- global[1] -> "__heap_base"
- global[2] -> "__data_end"
Joan Andrés commented
Solution?
Mohamadreza Nakhleh commented
Solution?
you should use a combination of C and C# :
__attribute__((__export_name__("my_function")))
void greet()
{
_start();
if (!method_HandleIncomingRequest) {
method_HandleIncomingRequest = lookup_dotnet_method("ConsoleApp5.dll", "main", "MainEntry", "Printsomething", -1);
assert(method_HandleIncomingRequest);
}
MonoObject* out_exc = NULL;
mono_wasm_invoke_method (method_HandleIncomingRequest, NULL, NULL, &out_exc);
assert (!out_exc);
}