Diesel: Tutorial roadblock: "Getting Started" PostgreSQL library linking fails on Windows when doing `cargo install diesel_cli --no-default-features postgres`

Created on 14 Oct 2018  路  16Comments  路  Source: diesel-rs/diesel

Setup

Versions

  • Rust: rustc 1.30.0-nightly (cb6d2dfa8 2018-09-16)
  • Diesel: diesel_cli
  • Database: postgres
  • Operating System Windows 10

Feature Flags

  • diesel: postgres

Problem Description

The tutorial is not "smooth" once the user hits this roadblock. Quick Google searches result in not being able to find how to extend the path for cargo install easily. A reasonable person at a beginner level will be stumped, scaring people off of Diesel's tutorial.

Note: adding the bin directory under PostgreSQL in Program Files to my path caused the installation to succeed. Perhaps adding this information to the tutorial might be useful.

What are you trying to accomplish?

Perform installation steps according to the tutorial here: http://diesel.rs/guides/getting-started/

What is the expected output?

Installing the package.

What is the actual output?

PS C:\Users\aytas\my-own-game> cargo install diesel_cli --no-default-features --features postgres
    Updating crates.io index
  Installing diesel_cli v1.3.1
   Compiling proc-macro2 v0.4.20
   Compiling version_check v0.1.5
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling unicode-xid v0.1.0
   Compiling winapi v0.3.6
   Compiling cfg-if v0.1.5
   Compiling num-traits v0.2.6
   Compiling pq-sys v0.4.6
   Compiling unicode-xid v0.0.4
   Compiling libc v0.2.43
   Compiling serde v1.0.79
   Compiling rand_core v0.3.0
   Compiling quote v0.3.15
   Compiling matches v0.1.8
   Compiling ucd-util v0.1.1
   Compiling regex v0.2.11
   Compiling num-integer v0.1.39
   Compiling rustc-demangle v0.1.9
   Compiling bitflags v1.0.4
   Compiling utf8-ranges v1.0.1
   Compiling byteorder v1.2.6
   Compiling unicode-width v0.1.5
   Compiling unicode-normalization v0.1.7
   Compiling vec_map v0.8.1
   Compiling percent-encoding v1.0.1
   Compiling strsim v0.7.0
   Compiling proc-macro2 v0.3.8
   Compiling synom v0.11.3
   Compiling unicode-bidi v0.3.4
   Compiling rand_core v0.2.2
   Compiling regex-syntax v0.5.6
   Compiling memchr v2.1.0
   Compiling lazy_static v1.1.0
   Compiling textwrap v0.10.0
   Compiling syn v0.11.11
   Compiling thread_local v0.3.6
   Compiling aho-corasick v0.6.8
   Compiling quote v0.5.2
   Compiling quote v0.6.8
   Compiling syn v0.13.11
   Compiling backtrace v0.3.9
   Compiling remove_dir_all v0.5.1
   Compiling rand v0.5.5
   Compiling atty v0.2.11
   Compiling time v0.1.40
   Compiling syn v0.15.10
   Compiling error-chain v0.10.0
   Compiling clap v2.32.0
   Compiling chrono v0.4.6
   Compiling derive-error-chain v0.10.1
   Compiling tempfile v3.0.4
   Compiling diesel_derives v1.3.0
   Compiling dotenv v0.10.1
   Compiling serde_derive v1.0.79
   Compiling idna v0.1.5
   Compiling diesel v1.3.3
   Compiling url v1.7.1
   Compiling migrations_internals v1.3.0
   Compiling toml v0.4.8
   Compiling infer_schema_internals v1.3.0
   Compiling diesel_cli v1.3.1
error: linking with `gcc` failed: exit code: 1
  |
  = note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\crt2.o" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.0.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.1.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.10.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.11.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.12.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.13.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.14.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.15.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.2.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.3.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.4.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.5.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.6.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.7.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.8.rcgu.o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.diesel.ls5jkkaa-cgu.9.rcgu.o" "-o" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.exe" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\diesel-71a8e8e6ae8b8c99.19ynnub55whocp43.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps" "-L" "C:\\Users\\aytas\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\winapi-x86_64-pc-windows-gnu-0.4.0\\lib" "-L" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\liburl-47c9e5f403f9786f.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libpercent_encoding-96620728ae92a6c9.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libidna-9a127281e20339b6.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libunicode_normalization-438301043f9f1b34.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libunicode_bidi-4d3198a32c1ee328.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libmatches-dbe72a2f8a6e3649.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libtoml-3e06271217709c5b.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libtempfile-dd469f1aee885e38.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libremove_dir_all-a7bf3687111454a7.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\librand-44f452657a2eadf1.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\librand_core-abadbdd4086dca8d.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\librand_core-3ca431ff82320fe3.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libmigrations_internals-d86c4f8d963b090f.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libinfer_schema_internals-223d3f47c9052cbe.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libserde-676ce6c6dacec52e.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libdotenv-bdd9b6715439d4aa.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libregex-799cd9b4b61020eb.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libutf8_ranges-c77eca197b9b604b.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libregex_syntax-757fa543a1553356.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libucd_util-6bafb0e247840aab.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libthread_local-816f4d01ed285cd9.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\liblazy_static-192b3ed7fae32f5e.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libaho_corasick-7eccf30c6641d338.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libmemchr-54f80c7ac919a901.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\liblibc-40d16202f4ef9163.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\liberror_chain-94dbe501f4c653c2.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libbacktrace-65ef0bb676be7e5a.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\librustc_demangle-bcb716b42ab1f4f5.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libcfg_if-8c2ea7cb920285e0.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libdiesel-aa349ccbc6c438a9.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libpq_sys-acc4638ab217c504.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libbyteorder-92c514b3c708d5e3.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libclap-c92c57cc0db73946.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libvec_map-c703a7fe931cd1be.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libtextwrap-17cce0cc74598fd3.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libunicode_width-05bff8ab5ece9a9b.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libstrsim-b480fdc98445b962.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libbitflags-5cfe802ede10325b.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libatty-525f0f218ecdfcd6.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libchrono-095e917bf8b312c5.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libnum_integer-b6c71207e6aed540.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libnum_traits-f0fc12e14078a720.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libtime-030ef2843018c658.rlib" "C:\\Users\\aytas\\AppData\\Local\\Temp\\cargo-install1lmnAV\\release\\deps\\libwinapi-5b2b69bc178c922c.rlib" "-Wl,--start-group" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-d75734fce9de8a47.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_unwind-23bcd7ed267060b8.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libunwind-7bb63bced97b6f87.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liblibc-236b4e813ef04dc3.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc_system-8a9aab5d37d8ce23.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-34265d7b30e25ca2.rlib" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcore-dd2b6f51b2cd5bd7.rlib" "-Wl,--end-group" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-0d29132b5d37b9ad.rlib" "-Wl,-Bdynamic" "-lpq" "-lwinapi_advapi32" "-lwinapi_credui" "-lwinapi_dbghelp" "-lwinapi_gdi32" "-lwinapi_kernel32" "-lwinapi_msimg32" "-lwinapi_opengl32" "-lwinapi_secur32" "-lwinapi_setupapi" "-lwinapi_user32" "-lwinapi_winspool" "-ladvapi32" "-lws2_32" "-luserenv" "-lshell32" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\Users\\aytas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: ld: cannot find -lpq


error: aborting due to previous error

error: failed to compile `diesel_cli v1.3.1`, intermediate artifacts can be found at `C:\Users\aytas\AppData\Local\Temp\cargo-install1lmnAV`

Caused by:
  Could not compile `diesel_cli`.

Are you seeing any additional errors?

No.

Steps to reproduce

  • Install PostgreSQL 10.5.
  • Run the command above.

Checklist

  • [x] I have already looked over the issue tracker for similar issues.
  • [x] This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)

Most helpful comment

copy C:/PostgreSQL/pg10/lib/libpq.dll & libpq.a to $(HOME)/.rustup/toolchains/[stable--msvc,gun]/lib/rustlib/x86/64-pc-windows.../lib
rename libpq.a -> libpq.lib

next compile works

All 16 comments

Feel free to submit a PR to https://github.com/sgrif/diesel.rs-website extending the note section there to directly list which native dependencies are required for which backends.

copy C:/PostgreSQL/pg10/lib/libpq.dll & libpq.a to $(HOME)/.rustup/toolchains/[stable--msvc,gun]/lib/rustlib/x86/64-pc-windows.../lib
rename libpq.a -> libpq.lib

next compile works

Here is one issue diesel migration run not works well.

Thank you so much @top1st

That fixed my issue with it not finding libpq.lib.

My console output if anyone is curious

>cargo install diesel_cli --no-default-features --features postgres
    Updating crates.io index
  Installing diesel_cli v1.3.1
   Compiling proc-macro2 v0.4.24
   Compiling semver-parser v0.7.0
   Compiling libc v0.2.46
   Compiling unicode-xid v0.1.0
   Compiling version_check v0.1.5
warning: not embedding natvis: lld-link may not support the flag

warning: not embedding natvis: lld-link may not support the flag

   Compiling winapi v0.3.6
   Compiling vcpkg v0.2.6
   Compiling autocfg v0.1.1
   Compiling num-traits v0.2.6
warning: not embedding natvis: lld-link may not support the flag

warning: not embedding natvis: lld-link may not support the flag

   Compiling unicode-xid v0.0.4
   Compiling cfg-if v0.1.6
   Compiling rustc-demangle v0.1.13
   Compiling num-integer v0.1.39
   Compiling serde v1.0.84
warning: not embedding natvis: lld-link may not support the flag

warning: not embedding natvis: lld-link may not support the flag

   Compiling ucd-util v0.1.3
   Compiling matches v0.1.8
   Compiling lazy_static v1.2.0
   Compiling regex v0.2.11
   Compiling rand_core v0.3.0
   Compiling quote v0.3.15
   Compiling unicode-width v0.1.5
   Compiling unicode-normalization v0.1.7
   Compiling byteorder v1.2.7
warning: not embedding natvis: lld-link may not support the flag

   Compiling utf8-ranges v1.0.2
   Compiling bitflags v1.0.4
   Compiling percent-encoding v1.0.1
   Compiling strsim v0.7.0
   Compiling vec_map v0.8.1
   Compiling proc-macro2 v0.3.8
   Compiling semver v0.9.0
   Compiling memchr v2.1.2
warning: not embedding natvis: lld-link may not support the flag

   Compiling synom v0.11.3
   Compiling rand_chacha v0.1.1
warning: not embedding natvis: lld-link may not support the flag

   Compiling backtrace v0.3.13
   Compiling rand v0.6.3
warning: not embedding natvis: lld-link may not support the flag

warning: not embedding natvis: lld-link may not support the flag

   Compiling pq-sys v0.4.6
   Compiling regex-syntax v0.5.6
   Compiling unicode-bidi v0.3.4
warning: not embedding natvis: lld-link may not support the flag

   Compiling thread_local v0.3.6
   Compiling textwrap v0.10.0
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.1
   Compiling rand_hc v0.1.0
   Compiling syn v0.11.11
   Compiling rustc_version v0.2.3
   Compiling quote v0.5.2
   Compiling quote v0.6.10
   Compiling rand_pcg v0.1.1
   Compiling rand_os v0.1.0
   Compiling atty v0.2.11
warning: not embedding natvis: lld-link may not support the flag

   Compiling remove_dir_all v0.5.1
   Compiling time v0.1.41
   Compiling idna v0.1.5
   Compiling aho-corasick v0.6.9
   Compiling syn v0.13.11
   Compiling syn v0.15.23
   Compiling derive-error-chain v0.10.1
   Compiling clap v2.32.0
   Compiling chrono v0.4.6
   Compiling error-chain v0.10.0
warning: not embedding natvis: lld-link may not support the flag

   Compiling url v1.7.2
   Compiling serde_derive v1.0.84
   Compiling diesel_derives v1.3.0
   Compiling dotenv v0.10.1
   Compiling tempfile v3.0.5
warning: not embedding natvis: lld-link may not support the flag

   Compiling diesel v1.3.3
warning: not embedding natvis: lld-link may not support the flag

   Compiling toml v0.4.10
   Compiling migrations_internals v1.3.0
   Compiling infer_schema_internals v1.3.0
   Compiling diesel_cli v1.3.1
warning: not embedding natvis: lld-link may not support the flag

error: linking with `lld-link.exe` failed: exit code: 1
  |
  = note: "lld-link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.0.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.1.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.10.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.11.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.12.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.13.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.14.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.15.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.2.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.3.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.4.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.5.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.6.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.7.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.8.rcgu.o" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.diesel.5t9v60oe-cgu.9.rcgu.o" "/OUT:C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.exe" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\diesel-2ec5483bb11140fd.3t4brw9uu7e5917u.rcgu.o" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps" "/LIBPATH:C:/POSTGR~1/pg10/lib" "/LIBPATH:C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\liburl-311c27da7eda9b23.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libpercent_encoding-d39a8d4ccfb1689f.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libidna-cdf2ec7486fe2e53.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libunicode_normalization-1a689ddddc68742d.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libunicode_bidi-160075525a9af67b.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libmatches-306296e784ed2044.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libtoml-8ee757ed99fca180.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libtempfile-3f98137ca5a85f7f.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libremove_dir_all-5fb2054af2954367.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand-20483952681cad83.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_xorshift-41d22a5c6587e3c1.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_pcg-403e4bb408bac56d.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_hc-856cdff7fee9f885.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_chacha-280ed9c94d9aa648.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_isaac-aff980eaa2e0b273.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_os-57c37edc1b30e732.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librand_core-c040c4bf6472128b.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libmigrations_internals-ad2660e9fb7ba3f6.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libinfer_schema_internals-0d77d3a21f991c8d.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libserde-0d476c92670d8967.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libdotenv-0d3ead47f2570ed8.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libregex-acc245407c006e45.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libutf8_ranges-393296c4e8921f2c.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libregex_syntax-52eab5ca3b3686b5.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libucd_util-3c34df3112141dbd.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libthread_local-d3320e4ca07141d2.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\liblazy_static-20b942af9413d46b.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libaho_corasick-5da8f3908f994d1e.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libmemchr-d3c2e3c742714911.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\liblibc-bda5ca0b3894b92c.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\liberror_chain-1da36336b39b2121.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libbacktrace-231589ff58f8134d.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\librustc_demangle-b967d08354ab3dea.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libcfg_if-05001ce65ae1165a.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libdiesel-b57f0a81e4f45a60.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libpq_sys-cb1af1c68ac17cd1.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libbyteorder-313da54f4620eb8e.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libclap-d2e3a7b7ff09e083.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libvec_map-50919a2d955cade3.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libtextwrap-42379df4d8ac8cb9.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libunicode_width-a6babce11606c624.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libstrsim-7761fa99b130e50d.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libbitflags-c3dfa588d6509e21.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libatty-5280a780c491ec6b.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libchrono-b2358e26e0fe0d54.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libnum_integer-271a4b863db8e4ef.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libnum_traits-1c9772dbd4a3fc65.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libtime-d06c3c96718bd16e.rlib" "C:\\Users\\Sammi\\AppData\\Local\\Temp\\cargo-install576IYL\\release\\deps\\libwinapi-06e1bccb79deb7a0.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-5b27a62c9f67f3de.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-4369007c1114ae91.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-717cd1192a64e0a2.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-b468418b9b4dfb1b.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-31879fae3e218342.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-396b96b15f25c29e.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-df063db6a7606a04.rlib" "C:\\Users\\Sammi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-df8513470b3bc4f5.rlib" "libpq.lib" "advapi32.lib" "credui.lib" "dbghelp.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "opengl32.lib" "secur32.lib" "setupapi.lib" "user32.lib" "winspool.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
  = note: lld-link.exe: error: could not open libpq.lib: no such file or directory


error: aborting due to previous error

error: failed to compile `diesel_cli v1.3.1`, intermediate artifacts can be found at `C:\Users\Sammi\AppData\Local\Temp\cargo-install576IYL`

Caused by:
  Could not compile `diesel_cli`.

This is all easier with vcpkg.

Install vcpkg and then install libpq using
vcpkg.exe install libpq:x64-windows

位  .\vcpkg.exe list
libpq:x64-windows                                  9.6.1-5          The official database access API of postgresql
libpq:x86-windows                                  9.6.1-5          The official database access API of postgresql
openssl-windows:x64-windows                        1.0.2q           OpenSSL is an open source project that provides ...
openssl-windows:x86-windows                        1.0.2q           OpenSSL is an open source project that provides ...
openssl:x64-windows                                0                OpenSSL is an open source project that provides ...
openssl:x86-windows                                0                OpenSSL is an open source project that provides ...

Use vcpkg-rs cli to ensure it detects the dependency:

vcpkg_cli.exe probe libpq
Found library libpq
Include paths:
  D:\Thirdparty\vcpkg\installed\x64-windows\include
Library paths:
  D:\Thirdparty\vcpkg\installed\x64-windows\lib
Runtime Library paths:
  D:\Thirdparty\vcpkg\installed\x64-windows\bin
Cargo metadata:
  cargo:rustc-link-search=native=D:\Thirdparty\vcpkg\installed\x64-windows\lib
  cargo:rustc-link-search=native=D:\Thirdparty\vcpkg\installed\x64-windows\bin
  cargo:rustc-link-lib=libpq
  cargo:rustc-link-lib=libeay32
  cargo:rustc-link-lib=ssleay32
Found DLLs:
  D:\Thirdparty\vcpkg\installed\x64-windows\bin\libpq.dll
  D:\Thirdparty\vcpkg\installed\x64-windows\bin\libeay32.dll
  D:\Thirdparty\vcpkg\installed\x64-windows\bin\ssleay32.dll

set VCPKGRS_DYNAMIC=1 to enable dynamic linking and then also export the vcpkg dll bin folder to PATH. It is much streamlined than copying dlls manually.

thx, I met the same problem and solve it with your method adding the bin directory under PostgreSQL in Program Files to my path

I'm not sure why the obvious hasn't been mentioned before but building windows diesel_cli for version 12 of postgres doesn't work. I have not found a single article on the diesel site (or any other) to explain this.

fatal error LNK1107: invalid or corrupt file: cannot read at 0x3549C

The libpq.lib is x64 and diesel currently only compiles using the 32bit linker (why, I'm not sure). The solution is to download the 32bit version 10 zip file here: https://www.enterprisedb.com/download-postgresql-binaries

Put the libpq.lib into the

"...rustup\toolchains\stable-i686-pc-windows-msvc\lib\rustlib\i686-pc-windows-msvc\lib"

toolchain and run (note diesel default compilation to the stable toolchain):

cargo install diesel_cli --no-default-features --features postgres

If like me, you want to keep your version 12 Postgres, you will now need to manually copy the 32 bit dlls to the cargo bin directory (don't copy them into windows/system32 otherwise you might corrupt your Postgres 12 install) so diesel.exe can run properly:

libcrypto-1_1.dll
libiconv-2.dll
libintl-8.dll
libpq.dll
libssl-1_1.dll

@oraclerob I've use locally postgres 12, so I can ensure you that it does work with that version.

The libpq.lib is x64 and diesel currently only compiles using the 32bit linker (why, I'm not sure). The solution is to download the 32bit version 10 zip file here: https://www.enterprisedb.com/download-postgresql-binaries

Sounds like a duplicate of #2280. If you use a 32 bit target you cannot link a 64 bit library. That's not an diesel issue, that's an issue with your setup.

Additionally: This is a issue tracker. It's for tracking issues and feature requests, not for doing support here. Please ask such questions in our gitter channel or in our forum.

Thankyou @weiznich I understand this is not a support forum and agree we shouldn't be doing support steps here, but after spending a day in frustration I thought my information will be useful to others. I'm sorry to say that I actually think that this is a cargo/diesel issue - because I followed step by step instructions exactly. My target is not 32bit at all. My setup is purely x64 so I'm not sure why when running:

cargo install diesel_cli --no-default-features --features postgres

That the wrong linker is being chosen. You will also note, I never got the obvious error (from the other issue) in the duplicate issue I got this error which is less obvious:

fatal error LNK1107: invalid or corrupt file: cannot read at 0x3549C

That lead me to a wild goose chase on library paths. I have 64bit visual studio 2015 installed so it is still a mystery why I was getting a linking error.

There is a successful CI build with postgresql 12 on windows (64bit). Therefore I do not consider this as issue with diesel. If you can come up with a set of steps that reproduce that issue reliable on a different system please open a new issue.

Having the exact same issue. Spent a whole day figuring out why my all 64 machine is recognized as x86, still no answer.

@askjiang As already stated above: This is a issue tracker. It's for tracking issues and feature requests, not for doing support here. Please ask such questions in our gitter channel or in our forum.

I made this issue just for the tutorial. diesel obviously work with PostgreSQL but I just thought I should at least bring up that the tutorial instructions are not 100% successful all the time.

@weiznich I've managed to get a personal setup with SQLite3 instead. Personally, I think SQLite3 is easier for beginners to get started with since it's a smaller and simpler SQL implementation, though less proper and complete.

On another note, if you'd like, I'd be willing to take the existing resources and write a tutorial based on SQLite3, also including some steps for installation and generation of DLLs for Windows as well. The docs are currently Linux-focused, but I do my primary development with nightly-x86_64-pc-windows-msvc (default), rustc 1.45.0-nightly (7ced01a73 2020-04-30).

@CinchBlue Any help with the documentation would be welcome. For the sqlite case the possible easiest setup is to just use the bundled feature on diesel_cli / libsqlite3-sys (for diesel itself) to just build sqlite as part of cargo build. That prevents that you need to worry about dependencies at all.
As a long term goal I would like to remove all other native dependencies (or at least have them behind feature flags) so that both postgres and mysql use their native rust client crates. For postgres there is already https://github.com/diesel-rs/diesel/pull/2257 for mysql a similar implementation based on the mysql crate should be possible. Any help here would also be appreciated, but that's something for after the 2.0 release.

Basically a duplicate of #1344

Was this page helpful?
0 / 5 - 0 ratings