Build errors with crate diesel_migrations

I've just added the dependency diesel_migrations to my project

diesel = { version = "1.4.4", features = ["postgres", "uuidv07"] }
diesel_migrations = "1.4.0"

and I'm encountering these errors when attempting to build locally.

    Compiling diesel_migrations v1.4.0
error: dlopen(/Users/michaelsorenson/github/auth/server/target/debug/deps/libmigrations_macros-57ba425941050147.dylib, 0x0005): Library not loaded: @rpath/libpq.5.dylib
         Referenced from: /Users/michaelsorenson/github/auth/server/target/debug/deps/libmigrations_macros-57ba425941050147.dylib
         Reason: tried: '/Users/michaelsorenson/.rustup/toolchains/stable-aarch64-apple-darwin/lib/../lib/libpq.5.dylib' (no such file), '/Users/michaelsorenson/.rustup/toolchains/stable-aarch64-apple-darwin/bin/../lib/libpq.5.dylib' (no such file), '/Users/michaelsorenson/.rustup/toolchains/stable-aarch64-apple-darwin/lib/libpq.5.dylib' (no such file), '/Users/michaelsorenson/github/auth/server/target/debug/deps/libpq.5.dylib' (no such file), '/Users/michaelsorenson/.rustup/toolchains/stable-aarch64-apple-darwin/lib/libpq.5.dylib' (no such file), '/Users/michaelsorenson/.rustup/toolchains/stable-aarch64-apple-darwin/lib/libpq.5.dylib' (no such file), '/Users/michaelsorenson/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file)
  --> /Users/michaelsorenson/.cargo/registry/src/
82 | extern crate migrations_macros;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `diesel_migrations` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

Additionally the RSL in vscode is giving this error on the import

extern location for diesel_migrations does not exist:

I previously had an error with libpq not being found when building the dependency diesel with the feature postgres, but I was able to add the library path to the build. I created this file to add the library path only when building on my laptop, but it appears this path is not being used in the build failure shown above.

use std::env;

fn main() {
    let target = env::var_os("TARGET").unwrap().into_string().unwrap();
    if target.as_str() == "aarch64-apple-darwin" {
        let path_prefix: String = env::var_os("CONDA_PREFIX").unwrap().into_string().unwrap();
        println!("cargo:rustc-link-arg=-Wl,-rpath,{}/lib", path_prefix);

This application is also built into a docker image, and there are no problems with building and running the application in the docker image.

I have solved the errors I was encountering by using the environment variable DYLD_FALLBACK_LIBRARY_PATH to add the path to the library. Instead of the file I'm using the environment variable like so.


Additionally I was able fix the errors I was seeing in vscode by adding this workspace setting. This allowed the build to succeed when running the tests from vscode.

    "terminal.integrated.env.osx": {

I have also switched to using the rust-analyzer plugin in vscode.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.