How to configure rustc-link-lib on OS X (libproj.a proj4)

A question about RUSTFLAGS or other methods of configuring rustc-link-lib on OS X.


  • OS X 10.15
  • Rust 1.42 installed via rustup
  • Homebrew installed LLVM and Proj4 library.

I am wanting to build this crate with --all-features. All features enables Serde, Proj4 and PostGIS integrations. Here is my Proj installation:

> brew info proj
proj: stable 7.0.0 (bottled), HEAD
Cartographic Projections Library
Conflicts with:
  blast (because both install a `libproj.a` library)
/usr/local/Cellar/proj/7.0.0 (57 files, 15.2MB) *
  Poured from bottle on 2020-03-16 at 17:19:35

After git clone of then I did:

cargo build --all-features

At first it failed with a missing llvm-config, and I discovered that OS X only has a partial implementation of llvm? I installed llvm via homebrew, and then I have apparently a working llvm setup that Rust can use.

> cargo build --all-features
   Compiling proj-sys v0.12.2
error: failed to run custom build command for `proj-sys v0.12.2`

Caused by:
  process didn't exit successfully: `.../geo/target/debug/build/proj-sys-41f3df0f82a014a5/build-script-build` (exit code: 101)
--- stdout

--- stderr
wrapper.h:1:10: fatal error: 'proj.h' file not found
wrapper.h:1:10: fatal error: 'proj.h' file not found, err: true

Aha! So I know from compiling C software in the past, that I need to tell rustc-link-lib where to find my Proj library because it's installed via Homebrew in a nonstandard location.

After reading the cargo docs and a few stackoverflow articles, I tried this RUSTFLAGS setting but got the same error:

RUSTFLAGS="-L native=/usr/local/Cellar/proj/7.0.0" cargo build --all-features

Now I am thinking I need to add some -C link-args... as well. Or possibly a -I for include. Various other environment variables? Should I remove the -L?

Any suggestions would be much appreciated!
Also I am curious what would be your thought process/mental model for solving something like this?

You typically don't touch any of these flags, and have no control of include paths or rust-link-lib from "outside".

It's responsibility of the sys crate that pulls in a library to ensure it always finds it and sets everything up correctly.

In this case, the proj-sys is supposed to find Homebrew's path and headers. If it doesn't, file a bug there. The crate could at least use pkg_config to discover the right include paths to use in its

1 Like

Thanks @kornel, will do. :+1:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.