Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't compile rust program

Tags:

rust

I'm new to rust and made a simple rust program(hello world). I installed rust and Visual Studio from here - https://visualstudio.microsoft.com/downloads/ and restarted the device. However when I type in rustc <path> on command prompt, I get:

error: linker `link.exe` not found
  |
  = note: The system cannot find the file specified. (os error 2)

note: the msvc targets depend on the msvc linker but `link.exe` was not found

note: please ensure that VS 2013, VS 2015 or VS 2017 was installed with the Visual C++ option

error: aborting due to previous error

What's wrong?

Update

I updated my system path to include C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\bin\Hostx64\x64, but now it gives this error:

error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-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\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-b2f27b8d08c4688f.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-9c73c9c2e052b2f1.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-7a588e8fa018f6bc.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-74b71f441b8acffe.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-42efce06651eab9c.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-7518db6030684168.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-f7edde5930d50b47.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-30189c8e78e151e8.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-5f5719f1cab83a12.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-f297c401e81b90c6.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-f8c80c1aefab6a32.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6d66b6e58725d3ed.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-1f6a73e107798f53.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'advapi32.lib'


error: aborting due to previous error
like image 915
Sid Avatar asked Sep 15 '19 08:09

Sid


People also ask

How do you compile Rust?

On Linux or macOS, enter the following commands to compile and run the file: $ rustc main.rs $ ./main Hello, world! On Windows, enter the command .\main.exe instead of ./main : > rustc main.rs > .\main.exe Hello, world!

Does Rust require AC compiler?

Rust needs C compiler because rustc cannot compile C code when one uses C libraries.

How do you run the Rust app?

To start using Rust, download the installer, then run the program and follow the onscreen instructions. You may need to install the Visual Studio C++ Build tools when prompted to do so. If you are not on Windows see "Other Installation Methods".


1 Answers

This reports your exact problem. So the solution seems to use VS installer and installing C++ for Desktop Module.

Use of rustup is a matter of convenience but shouldn't be mandatory.

like image 118
sancho.s ReinstateMonicaCellio Avatar answered Sep 17 '22 17:09

sancho.s ReinstateMonicaCellio