I made a simple C equivalent program, compiled it using gcc via this command gcc learning.c -o learning.exe and it worked just fine on both Windows 7 and Windows 10 on VM.
here is the source code for C:
#include <stdio.h>
int main()
{
printf("Hello world");
}
How would I compile without needing such dependencies or something to avoid getting such errors?
No idea really but I bet that VCRUNTIM140.dll is part of the Microsoft C compiler MSVC installation.
Suggest installing MSVC to some Windows machine then copying it to you VMs.
What if I want to run my applications without getting the user to install MSVC? Like with other languages? Its quite weird why Rust doesn't work but C works just fine?
I'm not totally sure but GCC also has a "run time" C library, libcrt, which I gets linked statically into the executable. I have no idea what Windows does with a dynamically loaded crt.
In case anyone is wondering, the C "run time" is hardly worthy of the name, it only sets up the stack and such before calling your main. Soo how small it can be: crt0 - Wikipedia
A bit of a misnomer really as it does not actually do anything whilst your code is running, only waits for it to return!
As far as I understand typically Windows programs come as a package containing all the DLLs they need, presumably including that one, just so they get the versions of the DLL's they need. This package being a self extracting installer. Think of what happens every time you have installed a Windows application from a downloaded install.exe.
What you want to do is statically link vcruntime. You can do that by making a .cargo/config.toml configuration file and putting something like this in to it:
# Windows 64 bit programs
[target.x86_64-pc-windows-msvc]
rustflags = [
"-C", "link-arg=libvcruntime.lib"
]
# Windows 32 bit programs
[target.i686-pc-windows-msvc]
rustflags = [
"-C", "link-arg=libvcruntime.lib"
]
Edit: You can make this configuration the default for all your programs by putting the config.toml into the %USERPROFILE%\.cargo\ folder.
This is normal for Windows. Visual Studio by design produces binaries that do not work on stock installation of Windows! Instead, you're supposed to bundle "VS Redistributable" with your application's installer, like this one:
You can work around it in Rust by requiring static linking with the Visual Studio runtime:
If you want to compile on Linux for Windows, you will have to use the Mingw toolchain instead of MSVC toolchain. This toolchain is also available on Windows. (x86_64-pc-windows-gnu and i686-pc-windows-gnu)
I see, would it need to be dependent on VCrun (as currently I do need this installed to get my
applicatins to work) or would it work without the installation of such programs?
Like @ZiCog said, C doesn't really have a "runtime", but Rust does have a comprehensive standard library and maybe that is what depends on libvcruntime.dll. I don't know.
That's great!
No, in the case of C it just doesn't depend on VCRuntime at all.
I'm pretty sure that if you install MingW and then compile with cargo build --target x86_64-pc-windows-gnu that it won't depend on any external DLLs.
On Linux I install MingW and cross-compile for windows with the --target x86_64-pc-windows-gnu and it works on a completely fresh Windows VM. I'm assuming that if you compile for x86_64-pc-windows-gnu on Windows the result should be similar.
To be precise, Rust uses vcruntime for its implementations of memcmp, memcpy, memmove and memset. It also uses some of the exception handling infrastructure (i.e. __CxxFrameHandler3 and _CxxThrowException) to implement panics. These could all be rewritten in Rust but they tend to be highly optimized for the platform so it makes sense to use the ones Microsoft gives you.
I'm not sure why it isn't static linked by default, at least on release builds. Maybe it mess with someone's workflow. Though it would at least be helpful to copy the necessary dll to the output folder.