Search code examples
rustrust-cargorust-diesel

Problems with setting up diesel for Rust


I have the following problems:

If I execute the following command:
diesel setup
it throws me:
requires the postgres feature but it's not enabled
But my Cargo.toml looks like this:
diesel = { version = "1.4.4", features = ["postgres", "r2d2", "chrono", "uuid"] }

So now I thought well maybe I installed something wrong and when I try to run:
cargo install diesel_cli -no--default-features --features postgres

it tells me:
linking with "link.exe" failed: exit code: 1181
...
...
"libpq.lib" cant be opened

tried to reinstall, didnt work, thought it would work, gave me a new error


Solution

  • For linux ubuntu you need to install libq-dev

    sudo apt install libpq-dev
    

    For windows you need to either add postgres lib folder to env variables, for example:

    PQ_LIB_DIR="C:\Program Files\PostgreSQL\14\lib"
    

    or simply copy libpq.lib to

    C:\Users\<username>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib