Cross compiling with native dependencies

I'm trying to cross-compile my application from a Linux-x86 host to a Linux-armv7 target. As far as I can tell I have everything set up correctly (well partially) since I can cross compile and execute an application with no native dependencies. The problem comes when I add Diesel with a Postgresql backend. When I do that, I see the following link error:

 error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1
   = note: "arm-linux-gnueabihf-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/home/gamroth/.rustup/toolchains/stable-x86_64-unkn
 .... lots of snipped text here ....
  = note: /usr/lib/x86_64-linux-gnu/ file not recognized: File format not recognized
           collect2: error: ld returned 1 exit status

I'm confused about this part -- why is the compiler looking at /usr/lib/x86_64-linux-gnu/ for libraries instead of /usr/lib/arm-linux-gnueabihf/. I've installed the armv7 dependencies I need to that location.

A couple of things I've tried:

Standard cross compile build:

$ cargo build --target=armv7-unknown-linux-gnueabihf

Setting the link path as an env variable:

$ RUSTFLAGS='-L /usr/lib/arm-linux-gnueabihf/' cargo build --target=armv7-unknown-linux-gnueabihf

Both of these give me the same error message from above.

Is there something I'm doing wrong here? I'm not even sure why I need the shared library installed to compile. I'm especially not sure why the compiler/linker is even looking at /usr/lib/x86_64-linux-gnu for libraries and how I can change that.

I think this is an issue with the pg-sys crate? I noticed that in target/armv7-unknown-linux-gnueabihf/debug/build/pq-sys-xxxx/output there is this line:


Changing that to:


Makes the build work. Of course, this isn't really a reasonable workaround so hopefully somebody has an idea. Maybe a problem with pq-sys?

@thebeekeeper Did you ever resolve this fully? I am getting the same on a different lib.

Unfortunately, not really. It looks like I ended up just not using Diesel for my application. I'm using the postgres crate, and that's cross-compiling fine. A little surprising since I'd expect that one to use pg-sys too, but maybe it's a different version.