Unable to link hello_world program on Windows: / usr / bin / link: optional operand
I installed Rust on a Windows 10 machine with rustup-init.exe - the method recommended in The Book of Rust . The installer told me that Rust requires the C-runtime VS2013 or newer. I have VS2017 installed, I assumed that Rust does not support VS2017 yet, and therefore agreed to install the C-runtime. Installation completed successfully.
main.rs
:
fn main() {
println!("Hello, world!");
}
Compilation:
> rustc main.rs error: linking with `link.exe` failed: exit code: 1 | = note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "main.0.o" "/OUT:main.exe" "/OPT:REF,NOICF" "/DEBUG" "/LIBPATH:C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-0a78323911070f99.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-c279a51d66700350.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-d7bf31a4ca1ea637.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-d367c3ba0db49600.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d4bf02140c11dcb.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-add7a84d7e82d084.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-84688accbc86d6b7.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-fe2e68b21f0bdd7a.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-7fc0381594c93f56.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-ea9d77e7c23fe65c.rlib" "C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-91b619d34dd1f5aa.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib" = note: /usr/bin/link: extra operand '/LIBPATH:C:\\Users\\***\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib' Try '/usr/bin/link --help' for more information. error: aborting due to previous error
link.exe
LIBPATH
arg is specified twice.
What's happening?
> rustc --version rustc 1.17.0 (56124baa9 2017-04-24)
source to share
As the rustup documentation says:
As mentioned on the Rust download page, there are two ABIs on Windows: the native (MSVC) ABI used by Visual Studio and the GNU ABI used by the GCC toolchain. Which version of Rust you need depends a lot on which C / C ++ libraries you want to interoperate: the MSVC Rust assembly is used to interact with software built by Visual Studio; the GNU build is used to interact with GNU software built using the MinGW / MSYS2 toolbox.
You have installed the MSVC programming chain. However, you run the compiler in a command shell, where it link.exe
does not point to the MSVC linker, but instead to the GNU toolchain - MSVC does not call its linker, /usr/bin/link
or uses options such as --help
!
You should configure your shell to have the MSVC linker main on the PATH, or switch to the GNU ABI if that's your goal.
Compare the help output of the two:
$ link --help Usage: link FILE1 FILE2 or: link OPTION Call the link function to create a link named FILE2 to an existing FILE1. --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/link> or available locally via: info '(coreutils) link invocation'
> link /help Microsoft (R) Incremental Linker Version 14.10.25017.0 Copyright (C) Microsoft Corporation. All rights reserved. For help on Linker, type `link /link' or `link' For help on Library Manager, type `link /lib' or `lib' For help on Dumper, type `link /dump' or `dumpbin' For help on Editor, type `link /edit' or `editbin' For help on CvtCIL, type `link /cvtcil'
I assumed Rust doesn't support VS2017 yet
It supports VS2017 just fine; as described in the 1.17 release notes , the problem is that it cannot find the MSVC installation automatically due to changes in the MSVC installation . Running the Rust compiler from within a shell with a normal environment works great.
source to share