<div dir="ltr">Hi Ved,<div><br></div><div>Yes, the trick is to declare the functions you want to import in your C source, then pass the `--allow-undefined` flag to wasm-ld when linking your wasm module. Here's a complete example:</div><div><br></div><div>hello.c:</div><div><br></div><div>```</div><div>int print_int(int x);</div><div><br></div><div>int do_work(int x) {</div><div>    print_int(x);</div><div>    return x;</div><div>}</div><div>```</div><div><br></div><div>clang -target wasm32 -c hello.c -o hello.o</div><div>wasm-ld hello.o -o hello.wasm --no-entry --allow-undefined --export=do_work</div><div><br></div><div>This will give you a wasm module that imports function "env" "print_int" and exports function "do_work". Note that Wasm uses a two-level namespace for imports, but the first level will always be "env" unless you annotate the function declaration with `__attribute__((import_module("my_other_namespace")))`.</div><div><br></div><div>Best,</div><div><br></div><div>Thomas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 13, 2020 at 8:04 PM Vedant Roy via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>Is there a method for importing functions from the Web Assembly runtime when writing C? I know Emscripten has support for calling JS functions from C code, but I was wondering if there's an easy way to do this without Emscripten (pure Clang)?</div><div><br></div><div>Best,</div><div>Ved</div><div><br></div><div><br></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>