Install Rust Diesel in Windows 10 and Fix Issue

Installing Diesel CLI in Windows 10 can be troublesome sometimes. When I did execute this command “cargo install diesel_cli –no-default-features –features postgres” and receive error message:

note: Non-UTF-8 output: LINK : fatal error LNK1181:error: linking with `link.exe` failed: exit code: 1181

I have tried to debug it with the various approach by:

So, I did reset my Windows 10 language and downloaded the gigantic Microsoft Visual Studio 2019 with “VC++ 2015.3 v14.00 (v140) toolset for desktop”. I did re-install rust with the hope it will solve the issue.

None of the above is works until I found someone wrote an article on how to install Diesel in Windows 10 and enable it’s CLI with the help of setup the local variable PATH.

Fyi, if you have problem with Visual Studio C++ tools, I suggest to support msvc rust toolchain required software Visual C++ Build or VS2015 Community Edition 

In this case, I’m using PostgreSQL. So, after no luck, I did add a new variable in Globe Variable Environment, add PQ_LIB_DIR and value to my new shiny Postgres. 

PQ_LIB_DIR = C:\Program Files\PostgreSQL\12\lib

After adding this variable, i did restart my Cmder and executed the cargo install diesel_cli. Voila! It succeeded!

If you are using another database, you can add these variables following your DB engine.


Btw, if you facing an issue that Diesel.exe LibPQ not found, the problem because the PostgreSQL bin is not set in the global environment path. Don’t forget to add your Postgres Bin path

Also, one of the user in Reddit, Paoda did shared tips for SQLite

If you are using sqlite3 as your database and you don’t mind bundling the C library with your library/binary you can have

libsqlite3-sys = { version = "0.17.3", features = ["bundled"]}

in your Cargo.toml. This way you don’t have to worry about creating a .lib to link to like you have to on Windows. And everything related to diesel in my Cargo.toml looks like this;

diesel = { version = "1.4", features = ["sqlite", "chrono"] }
libsqlite3-sys = { version = "0.17.3", features = ["bundled"]}
diesel_migrations = "1.4.0"

for installing diesel_cli you can use:

cargo install diesel_cli --no-default-features --features "sqlite-bundled"

Happy playing with Rust and Diesel!

4 replies on “Install Rust Diesel in Windows 10 and Fix Issue”

Leave a Reply

Your email address will not be published. Required fields are marked *