How canI libgfortran together with gfortran?

I have installed nixos.gfortran, but when I compile a f90 program with -lgfortran, it complains that it cannot find this lib.
I have tried gfortran.lib in default.nix, but neigher can be recognized.

I found that libgfortran exists in my nix/store:


But I don’t know how to add it into my default.nix.


gfortran is a compiler wrapper around gcc.
You can access the unwrapped version through the .cc attribute.
If you add to buildInputs this will add libgfortran to your compiler link path:

# save as shell.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "env";
  buildInputs = [
$ nix-shell
$ echo "int main() {}" > main.c
$ gcc -lgfortran -o main main.c