Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

rust

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?

like image 1000
user3338991 Avatar asked Jan 08 '20 14:01

user3338991


2 Answers

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

  • https://users.rust-lang.org/t/problems-with-installing-rust-on-windows/9349/22
    • http://asyncbulbs.blogspot.com/2017/06/workaround-for-rustc-with-new-visual.html
      • direct link to Build Tools (should work still) https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
  • https://github.com/rust-lang/rust/issues/43039#issuecomment-589321158
  • https://github.com/rust-lang/prev.rust-lang.org/issues/1015
like image 74
rofrol Avatar answered Sep 21 '22 10:09

rofrol


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.

like image 25
user3338991 Avatar answered Sep 17 '22 10:09

user3338991