DEV Community


Rust/Diesel: Fixing issues with setup

ssivakumar profile image Sivakumar Updated on ・2 min read

Hello There!. This is my first ever blog post.

Very recently, I have started exploring Rust language and I already have so much fun learning this language.

I was trying to do some basic database CRUD implementations in Rust and as you know, most famous framework for the same is Diesel .

Since I faced lots of issues while setting up Diesel on my local machine, I thought of putting it as blog post so that, it can be of useful to someone who will face similar issues of mine.

For your information, I am using Windows 10 operating system (64-bit) and Rust v1.45.0.

In case if you have not installed Rust with Visual C++ build tools , when you're trying to install Diesel framework, you may get some errors related to Linker.exe. It is better to install latest version of Microsoft Visual C++ build tools first and then re-install Rust on your computer.

Installing Diesel framework is a 2-step process.

Step 1: Install Diesel using CARGO

cargo install diesel
Enter fullscreen mode Exit fullscreen mode

As of writing of this post, Diesel supports MySQL, Postgres and SQLite. The above command expects all the client tools pre-exists on your computer.

If you have one of the client tools, you can use following command

cargo install diesel --no-default-features --features mysql postgres sqlite
Enter fullscreen mode Exit fullscreen mode

In my case, i am having Postgres so, i tried with

cargo install diesel --no-default-features --features postgres
Enter fullscreen mode Exit fullscreen mode

Initially, when i try the above command, I was getting following error

error: diesel = note: link : fatal error lnk1181: cannot open input file 'libpq.lib'
Enter fullscreen mode Exit fullscreen mode

After spending few minutes on google, I figured out, i need to setup environment variable named PQ_LIB_DIR mapped to lib directory of Postgres installation folder.

In my computer, I have Postgres installed on C:\Program Files\Postgres\12\. So, I setup PQ_LIB_DIR as C:\Program Files\Postgres\12\lib.

Due to spaces in the folder name, cargo install diesel threw me error message. So, I had to correct it like c:/Program Files/Postgres/12/lib to solve the first level of issue.

Step 2: Setting up Diesel

To setup Diesel, we need run following command

diesel setup
Enter fullscreen mode Exit fullscreen mode

It throws me following error:

The code execution cannot proceed because libpq.dll was not found.
Enter fullscreen mode Exit fullscreen mode

Even though, I had added PQ_LIB_DIR environment variable, I got the above error. After a little search, I found out that, diesel is not able to find the libpq.dll from folders listed under PATH variable. After added PQ_LIB_DIR to PATH variable, that error was gone.

Then, I was getting another error:

The code execution cannot proceed because libssl-1_1-x64.dll was not found.
Enter fullscreen mode Exit fullscreen mode

This dll file is shipped alongwith postgres and it can be found under BIN folder. After I have added Postgres' BIN folder to PATH variable, diesel setup was completed successfully.

Hope you find the above post useful. Please share your feedback in case if i miss any other points.

Happy reading!!!

Discussion (0)

Forem Open with the Forem app