How do I resolve "library not found for -lgfortran" when compiling a Rust application on macOS?

Viewed 3632

I am trying to build a Rust app and I get the below when trying to build. This happened after I installed ndarray-linalg and ndarray.

I installed gcc and openvc. I am on macOS.

 = note: ld: library not found for -lgfortran
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

How do I resolve this?

which gfortran
/usr/local/bin/gfortran

I found the library here:

ls /usr/local/Cellar/gcc/8.2.0/lib/gcc/8/libgfortran.*
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/libgfortran.5.dylib    
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/libgfortran.dylib
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/libgfortran.a      
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/libgfortran.spec
ldconfig -p | grep fortran
-bash: ldconfig: command not found

And also ran the below:

brew reinstall gcc

How can I make sure Rust will find it?

1 Answers

Check first if any of the env variables are set

  • DYLD_LIBRARY_PATH
  • DYLD_FALLBACK_LIBRARY_PATH

These variables tell the compiler where to look for libraries installed on the system. Built-in libraries are usually placed in /usr/lib, and homebrew places them in /usr/local/lib. So these should be in your lib path.

If for some reason you cant find your library there you can try

export DYLD_LIBARY_PATH=$DYLD_LIBARY_PATH:/usr/local/Cellar/gcc/8.2.0/lib/gcc/8

and if that does not work try with the other variables.

Related