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 geterror LNK2019: unresolved external symbol __imp_wasm_config_new referenced in function wahe_module_init
even though the unresolved symbol appears to be inwasmtime.lib
. Only linking withwasmtime.dll.lib
does anything and then of course it still requires the DLL. Why does this bigwasmtime.lib
even exist if it does nothing? Removing it appears to change nothing at all.
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?
Photosounder commented on issue #7808:
Thanks, I added
#define WASM_API_EXTERN
and also#define WASI_API_EXTERN
(needed for the same reason bywasi_
functions) above#include <wasmtime.h>
in my code and it works. It first complained about lots of unresolved symbols which were solved by linkingWs2_32.lib
,NtDll.lib
,Userenv.lib
andBcrypt.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.
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 geterror LNK2019: unresolved external symbol __imp_wasm_config_new referenced in function wahe_module_init
even though the unresolved symbol appears to be inwasmtime.lib
. Only linking withwasmtime.dll.lib
does anything and then of course it still requires the DLL. Why does this bigwasmtime.lib
even exist if it does nothing? Removing it appears to change nothing at all.
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!
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 bywasi_
functions) above#include <wasmtime.h>
in my code and it works. It first complained about lots of unresolved symbols which were solved by linkingWs2_32.lib
,NtDll.lib
,Userenv.lib
andBcrypt.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.
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: Dec 23 2024 at 12:05 UTC