Error: linking with `link.exe` failed: exit code: 1181

I am getting this error when trying to compile a Rocket project on Windows10. It was okay at first, doing very basic stuff, but when I try to add database connectivity, it fails with this error:

error: linking with link.exe failed: exit code: 1181

I have found notes about other people who have this issue, and have tried a few things to resolve. I have Visual Studio 2019 Community Edition and the Visual C++ Tools are installed, and can see link.exe in:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX64\x86

I have tried re-installing Rust. Originally I used 64-bit version, I am now on the 32-bit version.

I have next to no knowledge of Rust, so would appreciate any help.

Can you give more of the output when you try compiling? It sounds like there's a particular library it needs but can't find.

Here is the full, verbose output:

C:\Users\andyj\Documents\f2db>cargo run --verbose
Fresh version_check v0.9.3
Fresh cfg-if v1.0.0
Fresh yansi v0.5.0
Fresh unicode-xid v0.1.0
Fresh subtle v2.4.0
Fresh opaque-debug v0.3.0
Fresh unicode-xid v0.2.1
Fresh smallvec v1.6.1
Fresh tinyvec_macros v0.1.0
Fresh version_check v0.1.5
Fresh matches v0.1.8
Fresh cpuid-bool v0.2.0
Fresh byteorder v1.4.3
Fresh ppv-lite86 v0.2.10
Fresh autocfg v1.0.1
Fresh scopeguard v1.1.0
Fresh safemem v0.3.3
Fresh percent-encoding v1.0.1
Fresh cpuid-bool v0.1.2
Fresh typeable v0.1.2
Fresh vcpkg v0.2.11
Fresh traitobject v0.1.0
Fresh hashbrown v0.9.1
Fresh base64 v0.13.0
Fresh language-tags v0.2.2
Fresh percent-encoding v2.1.0
Fresh state v0.4.2
Fresh glob v0.3.0
Fresh base64 v0.12.3
Fresh instant v0.1.9
Fresh tinyvec v1.1.1
Fresh unicode-bidi v0.3.4
Fresh lock_api v0.4.2
Fresh base64 v0.9.3
Fresh typenum v1.13.0
Fresh winapi v0.3.9
Fresh proc-macro2 v0.4.30
Fresh proc-macro2 v1.0.24
Fresh log v0.4.14
Fresh libc v0.2.90
Fresh bitflags v1.2.1
Fresh getrandom v0.2.2
Fresh unicode-normalization v0.1.17
Fresh httparse v1.3.5
Fresh generic-array v0.14.4
Fresh parking_lot_core v0.8.3
Fresh winapi-util v0.1.5
Fresh atty v0.2.14
Fresh memchr v2.3.4
Fresh filetime v0.2.14
Fresh quote v0.6.13
Fresh quote v1.0.9
Fresh time v0.1.43
Fresh log v0.3.9
Fresh num_cpus v1.13.0
Fresh cipher v0.2.5
Fresh universal-hash v0.4.0
Fresh digest v0.9.0
Fresh rand_core v0.6.2
Fresh crypto-mac v0.10.0
Fresh aead v0.3.2
Fresh idna v0.1.5
Fresh block-buffer v0.9.0
Fresh unicase v1.4.2
Fresh parking_lot v0.11.1
Fresh indexmap v1.6.2
Fresh syn v0.15.44
Fresh syn v1.0.64
Fresh same-file v1.0.6
Fresh pq-sys v0.4.6
Fresh polyval v0.4.5
Fresh aes-soft v0.6.4
Fresh hmac v0.10.1
Fresh ctr v0.6.0
Fresh rand_chacha v0.3.0
Fresh mime v0.2.6
Fresh devise_core v0.2.0
Fresh sha2 v0.9.3
Fresh pear_codegen v0.1.4
Fresh url v1.7.2
Fresh serde_derive v1.0.125
Fresh scheduled-thread-pool v0.2.5
Fresh diesel_derives v1.4.1
Fresh walkdir v2.3.1
Fresh aes v0.6.0
Fresh ghash v0.3.1
Fresh devise_codegen v0.2.0
Fresh rand v0.8.3
Fresh hkdf v0.10.0
Fresh pear v0.1.4
Fresh hyper v0.10.16
Fresh serde v1.0.125
Fresh r2d2 v0.8.9
Fresh notify v4.0.15
Fresh aes-gcm v0.8.0
Fresh devise v0.2.0
Fresh toml v0.4.10
Fresh diesel v1.4.6
Fresh cookie v0.11.4
Fresh rocket_contrib_codegen v0.4.7
Fresh rocket_http v0.4.7
Fresh rocket_codegen v0.4.7
Fresh rocket v0.4.7
Fresh rocket_contrib v0.4.7
Compiling f2db v0.1.0 (C:\Users\andyj\Documents\f2db)
Running rustc --crate-name f2db --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=4286ba8dd0d98cc4 --out-dir C:\Users\andyj\Documents\f2db\target\debug\deps -C incremental=C:\Users\andyj\Documents\f2db\target\debug\incremental -L dependency=C:\Users\andyj\Documents\f2db\target\debug\deps --extern f2db=C:\Users\andyj\Documents\f2db\target\debug\deps\libf2db-717ac34995739028.rlib --extern rocket=C:\Users\andyj\Documents\f2db\target\debug\deps\librocket-4d88719fdc5d3b2d.rlib --extern rocket_contrib=C:\Users\andyj\Documents\f2db\target\debug\deps\librocket_contrib-dbdbc5c6ee477e70.rlib --extern serde=C:\Users\andyj\Documents\f2db\target\debug\deps\libserde-4fad22d9fef8bed7.rlib
error: linking with link.exe failed: exit code: 1181
|
= note: "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.2tkmu9be7d6z43n9.rcgu.o" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.3q2o8311iudf526g.rcgu.o" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.40keqxzjyt5cfgsl.rcgu.o" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.4icfemkaz58unqiz.rcgu.o" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.j1ak25vlky5uytt.rcgu.o" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.nymxgtp1d6tlz65.rcgu.o" "/OUT:C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.exe" "C:\Users\andyj\Documents\f2db\target\debug\deps\f2db.dp91mjo6hvcdy4x.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\intrinsic.natvis" "/NATVIS:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\liballoc.natvis" "/NATVIS:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\libcore.natvis" "/NATVIS:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\etc\libstd.natvis" "/LIBPATH:C:\Users\andyj\Documents\f2db\target\debug\deps" "/LIBPATH:C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libf2db-717ac34995739028.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librocket_contrib-dbdbc5c6ee477e70.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libdiesel-80c12dd18f8a14f3.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libpq_sys-7965e5000b1de837.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libbitflags-4691a02cd52b2b39.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libr2d2-b706e305630874e0.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libscheduled_thread_pool-017536fe79fb8073.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libparking_lot-1e6a1c494fbf6765.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libparking_lot_core-782de13d2fa33a2f.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\liblock_api-2a2addd426590431.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libscopeguard-7d58122f9c0c1d3f.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libinstant-073a2a812cca075e.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librocket-4d88719fdc5d3b2d.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libatty-d507fa85f6a6aced.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libbase64-903f104f1880eb74.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libmemchr-811067f54081c723.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtoml-8e1d430c039cd94c.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libserde-4fad22d9fef8bed7.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libyansi-d581edbd91ac4f06.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librocket_http-92181df842926b2e.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libhyper-178e9f6eb635c348.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libmime-67ae135531b14b10.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\liblog-ed3fb0f06614fa8b.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\liblog-3340466743488f6d.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\liblanguage_tags-d83bb760ad285108.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtypeable-211ddf36dc689425.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtraitobject-18edc422ba417135.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libnum_cpus-b4775a370bfe60a1.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libhttparse-233c6dccae91c533.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libunicase-541fb1c63a6de849.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\liburl-d6161b6a61430832.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libidna-8b9bc7499643327b.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libunicode_normalization-094ef02255a29fe9.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtinyvec-e594999f8ef24b44.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtinyvec_macros-6a15acfe4bdb086a.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libunicode_bidi-1a1c78a1f60a57eb.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libmatches-5b318151d5ffa721.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libbase64-5099bbeb21311212.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libsafemem-f760e31389d31f1b.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libbyteorder-6ecf483c5c714465.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libunicode_xid-9643309744858c5c.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libstate-f7aaa70c96381f36.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libindexmap-be734921550774c3.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libhashbrown-0e69a4cd9d700a10.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcookie-39edc4e5c79ce33b.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libhkdf-2e80ebc8ae947bfe.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libhmac-1ef2ac2afcc8f4bf.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcrypto_mac-c0601ae81f12c19f.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libsha2-c1283a3ed506bfbd.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcpuid_bool-12761c24bafa8482.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libdigest-37a3f227e8d1e276.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libblock_buffer-587851f32528b023.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libaes_gcm-bda37c6810d007d7.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libghash-800fb60ad39dd554.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libpolyval-f2eea2af78acb936.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcpuid_bool-1b7b33c9cf06a269.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libuniversal_hash-bcaf3098abf08c04.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libsubtle-9e61af1a1d7203d9.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libctr-9b7387f819587b48.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libaes-79bbfe3ac4f714b5.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libaes_soft-a740a9ec07f30547.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libopaque_debug-ae995468febc0262.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcipher-28c0bc3671c9f058.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libaead-1b086be2d201c939.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libgeneric_array-1b37f4ee1bc8dae8.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtypenum-b94ae4ab71587d87.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libbase64-2afb6405dd542280.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librand-b69ab4bbb03925a7.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librand_chacha-aefed2f1939970df.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libppv_lite86-477b2154f0865365.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\librand_core-da196ab82a352381.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libgetrandom-de66b2b9ff2e60db.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libcfg_if-a7309519de2cc80c.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libtime-f49901d85546cc84.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libwinapi-c111cbd500ab050e.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libpercent_encoding-6770ef3260c168d7.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libsmallvec-5be80423043c4973.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libpercent_encoding-9e1527d235b40769.rlib" "C:\Users\andyj\Documents\f2db\target\debug\deps\libpear-a3158b6d59a550da.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-10b7e6d60550c4bc.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libpanic_unwind-027d075641110cd0.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_demangle-6aca15500a4c049d.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libhashbrown-3742f052ed45db81.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_alloc-ec473ab4f7f18d14.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libunwind-22220fcaa76d1a0d.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcfg_if-b99d159579768184.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liblibc-937a75dfa4d935e4.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liballoc-30937137cb83abb7.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_core-d454e7de92167dc4.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcore-51061a7c11411681.rlib" "C:\Users\andyj\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcompiler_builtins-d0c7e844decdcc15.rlib" "libpq.lib" "bcrypt.lib" "advapi32.lib" "cfgmgr32.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "opengl32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: LINK : fatal error LNK1181: cannot open input file 'libpq.lib'

error: aborting due to previous error

error: could not compile f2db

Caused by:
process didn't exit successfully: rustc --crate-name f2db --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=4286ba8dd0d98cc4 --out-dir C:\Users\andyj\Documents\f2db\target\debug\deps -C incremental=C:\Users\andyj\Documents\f2db\target\debug\incremental -L dependency=C:\Users\andyj\Documents\f2db\target\debug\deps --extern f2db=C:\Users\andyj\Documents\f2db\target\debug\deps\libf2db-717ac34995739028.rlib --extern rocket=C:\Users\andyj\Documents\f2db\target\debug\deps\librocket-4d88719fdc5d3b2d.rlib --extern rocket_contrib=C:\Users\andyj\Documents\f2db\target\debug\deps\librocket_contrib-dbdbc5c6ee477e70.rlib --extern serde=C:\Users\andyj\Documents\f2db\target\debug\deps\libserde-4fad22d9fef8bed7.rlib (exit code: 1)

cannot open input file 'libpq.lib'

Ok, so that's saying it can't find the library libpq.lib. I think that's the PostgreSQL library?

To be honest I'm not that familiar with Rocket.

I should have seen that! All the other posts about this issue led me to think it was an issue with link.exe, but this makes more sense. I think you are right that it is the PostgreSQL library (or part of it), that fits with what I was doing.