'Unable to compile Rust program: LNK1181: cannot open input file 'C:\\Program.obj'

I am getting the error:

C:\rust\hello_world\src>where link.exe
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x86\link.exe
C:\rust\hello_world\src>rustc main.rs

error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX64\\x86\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LARGEADDRESSAWARE" "/SAFESEH" "/LIBPATH:C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib" "main.main.7rcbfp3g-cgu.0.rcgu.o" "main.main.7rcbfp3g-cgu.1.rcgu.o" "main.main.7rcbfp3g-cgu.2.rcgu.o" "main.main.7rcbfp3g-cgu.3.rcgu.o" "main.main.7rcbfp3g-cgu.4.rcgu.o" "main.main.7rcbfp3g-cgu.5.rcgu.o" "/OUT:main.exe" "main.4s37gsrti678ik8u.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libstd-a2af7cbca70405c4.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libpanic_unwind-8f8ad41ed0b34354.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libhashbrown-3442ca764a847dfc.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-726244614f5a8f3a.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libbacktrace-29b7599014a92286.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\librustc_demangle-519f7f7caa7ec7f2.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libunwind-feba7334127a8724.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcfg_if-6d75d87de5ddb74c.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\liblibc-7dc5efd24952e919.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\liballoc-b95120d391119ce4.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\librustc_std_workspace_core-0e624f0b43962fb3.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcore-58985b8c03f907a8.rlib" "C:\\Users\\user\\.rustup\\toolchains\\stable-i686-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcompiler_builtins-27c1b248396c205c.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'C:\\Program.obj'

I've looked at other posts suggested by Stack Overflow as well as some Google results regarding this issue. I've tried to install and reinstall VS Community 2019 with C++ for desktop module, Visual Studio build tools with C++ build tools, the newest Windows 10 SDK with all options as well as the newest rustup-init installation. Where might my problem be?



Solution 1:[1]

After a lot of trial and error I discovered that I had previously installed mingw with GNU. Even if rust looked for link.exe in "...Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC...", it was using GNU version not MSVC version of some dependencies. So in my case using not default(which is for MSVC which comes with VS) installation, but an GNU platform specific rust installation from https://forge.rust-lang.org/infra/other-installation-methods.html worked for me. Maybe if someone experienced could explain the issue in normal terms for future reference.

Solution 2:[2]

You need to install Windows SDK. Download Visual C++ Build Tools from https://visualstudio.microsoft.com/downloads/ and select Windows SDK during install. Or if If you have already installed it:

Windows Settings > Apps > Microsoft Visual C++ Build Tools > Modify > Windows SDK

Solution 3:[3]

1.download these files https://www.sqlite.org/2022/sqlite-amalgamation-3380500.zip https://www.sqlite.org/2022/sqlite-dll-win64-x64-3380500.zip 2.extract in same directory 3.open Developer Command Prompt and go to directory of extracted files 4. excecute this code in Developer Command Prompt "lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64" 5.copy sqlite3.lib to C:\Users\Hadi\AppData\Local\Programs\Python\Python38\libs (for me python 3.8 is installed)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3338991
Solution 2
Solution 3 hadi faghihi