Stream: git-wasmtime

Topic: wasmtime / issue #7808 Static linking, C API on MSVC


view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 10:28):

Photosounder opened issue #7808:

I'm trying to statically link Wasmtime (C API) in my host program built with MSVC, but I can't do it. The perplexing thing is that we have this wasmtime.lib and it's 62 MB so you'd expect it to contain everything needed for linking, but when linking to it it's like it's not even there, we still get error LNK2019: unresolved external symbol __imp_wasm_config_new referenced in function wahe_module_init even though the unresolved symbol appears to be in wasmtime.lib. Only linking with wasmtime.dll.lib does anything and then of course it still requires the DLL. Why does this big wasmtime.lib even exist if it does nothing? Removing it appears to change nothing at all.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 16:08):

alexcrichton commented on issue #7808:

I'm not exactly an expert on linking on Windows, but you might be running into dllimport-vs-not. I believe that if the header file you're using is configured for dllimport which wasm.h is configured to do by default then the function must come from a DLL. In the case of static linking, however, that's not happening. If you pass -DWASM_API_EXTERN to your C compiler does it resolve this issue?

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 16:50):

Photosounder commented on issue #7808:

Thanks, I added #define WASM_API_EXTERN and also #define WASI_API_EXTERN (needed for the same reason by wasi_ functions) above #include <wasmtime.h> in my code and it works. It first complained about lots of unresolved symbols which were solved by linking Ws2_32.lib, NtDll.lib, Userenv.lib and Bcrypt.lib, so now it complies and it gives me a 5.4 MB .exe (instead of 40 kB) and it works fine without the DLL, but it gave me the following warning that wasn't there before:

1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

It's odd but I resolved it by adding LIBCMT to "Ignore Specific Default Libraries" (Properties > Linker > Input), I don't know if it's cause for concern.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 16:50):

Photosounder closed issue #7808:

I'm trying to statically link Wasmtime (C API) in my host program built with MSVC, but I can't do it. The perplexing thing is that we have this wasmtime.lib and it's 62 MB so you'd expect it to contain everything needed for linking, but when linking to it it's like it's not even there, we still get error LNK2019: unresolved external symbol __imp_wasm_config_new referenced in function wahe_module_init even though the unresolved symbol appears to be in wasmtime.lib. Only linking with wasmtime.dll.lib does anything and then of course it still requires the DLL. Why does this big wasmtime.lib even exist if it does nothing? Removing it appears to change nothing at all.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 17:23):

alexcrichton commented on issue #7808:

Alas I'm not sure how best to resolve that warning myself, but glad it's working for you at least!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 17:50):

Photosounder edited a comment on issue #7808:

Thanks, I added #define WASM_API_EXTERN and also #define WASI_API_EXTERN (needed for the same reason by wasi_ functions) above #include <wasmtime.h> in my code and it works. It first complained about lots of unresolved symbols which were solved by linking Ws2_32.lib, NtDll.lib, Userenv.lib and Bcrypt.lib, so now it compiles and it gives me a 5.4 MB .exe (instead of 40 kB) and it works fine without the DLL, but it gave me the following warning that wasn't there before:

1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

It's odd but I resolved it by adding LIBCMT to "Ignore Specific Default Libraries" (Properties > Linker > Input), I don't know if it's cause for concern.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2024 at 20:02):

Photosounder commented on issue #7808:

It turns out that the LIBCMT warning was due to compiling my project with "Runtime Library" still on "Multi-threaded DLL (/MD)" instead of "Multi-threaded (/MT)" like wasmtime.lib was.


Last updated: Nov 22 2024 at 16:03 UTC