title: GCC Cython refuses to link gfortran in outside conda environment
body: <p>I'm trying to make a package that binds Fortran code through Cython work outside of conda environments, like  Fedora 35 or a Ubuntu 18.04, the problem is that while building the extension, gcc refuses to link gfortran.</p>
  <p>setup.py:</p>
  <pre class="lang-py prettyprint-override"><code>cmd = &quot;make release&quot;
  subprocess.call(cmd, shell=True, stdout=open(os.devnull, 'wb'))
  
  ext1 = Extension(
      name='model',
      sources=['src/cython/model.pyx'],
      extra_compile_args=['-g', &quot;-static&quot;],
      libraries=['gfortran'],
      extra_link_args=[
          &quot;build/release/Utils.o&quot;, 
          &quot;build/release/Logger.o&quot;, 
          ...
      ]
  )
  
  setup(
    ...
    ext_modules=cythonize([ext1, ext2], compiler_directives={'embedsignature': True}),
    ...
  )
  </code></pre>
  <p>Makefile:</p>
  <pre><code>MKDIR          := mkdir -p
  LN             := ln -fs
  RM             := rm
  CP             := cp
  CD             := cd
  COMPILER       := gfortran
  
  GENERAL_FLAGS            := -std=f2003 -fall-intrinsics -fPIC -cpp -static
  RELEASE_FLAGS            := ${GENERAL_FLAGS} -Ofast
  
  SRC_DIR                      := src/model
  BUILD_DIR                    := build
  RELEASE_DIR                  := release
  DIST_DIR                     := dist
  
  PROGRAM_NAME              := model
  
  FILES := Utils.o Logger.o ...
  
  .PHONY: release
  
  debug: FLAGS       := ${DEBUG_FLAGS} -o
  debug: OBJ_DIR     := ${BUILD_DIR}/${DEBUG_DIR}
  debug: PROGRAM_DIR := ${DIST_DIR}/${DEBUG_DIR}
  debug: PROGRAM     := ${PROGRAM_DIR}/${PROGRAM_NAME}
  debug: COMP        := ${COMPILER}
  
  release: FLAGS       := ${RELEASE_FLAGS} -o
  release: OBJ_DIR     := ${BUILD_DIR}/${RELEASE_DIR}
  release: PROGRAM_DIR := ${DIST_DIR}/${RELEASE_DIR}
  release: PROGRAM     := ${PROGRAM_DIR}/${PROGRAM_NAME}
  release: COMP        := ${COMPILER}
  
  .SECONDEXPANSION:
  release: $${FILES}
        ${MKDIR} ${PROGRAM_DIR}
        ${COMP} -I ${OBJ_DIR} ${FLAGS} ${PROGRAM} $(FILES:%o=${OBJ_DIR}/%o)
        ${LN} ${PROGRAM} $@-link
  
  %.o: ${SRC_DIR}/%.f90
      ${MKDIR} ${OBJ_DIR}
      ${COMP} -J ${OBJ_DIR} -c ${FLAGS} ${OBJ_DIR}/$@ $&lt;
  
  </code></pre>
  <h2>Inside conda env:</h2>
  <p>nm model.cpython-38-x86_64-linux-gnu.so --undefined:</p>
  <pre><code>                 w __cxa_finalize@@GLIBC_2.2.5
                   U free@@GLIBC_2.2.5
                   U _gfortran_adjustl@@GFORTRAN_8
                   U _gfortran_compare_string@@GFORTRAN_8
                   U _gfortran_concat_string@@GFORTRAN_8
                   U _gfortran_exit_i4@@GFORTRAN_8
                   U _gfortran_fdate_sub@@GFORTRAN_8
                   U _gfortran_getarg_i4@@GFORTRAN_8
                   U _gfortran_iargc@@GFORTRAN_8
                   U _gfortran_select_string@@GFORTRAN_8
                   U _gfortran_st_inquire@@GFORTRAN_8
                   U _gfortran_st_open@@GFORTRAN_8
                   U _gfortran_st_read_done@@GFORTRAN_8
                   U _gfortran_st_read@@GFORTRAN_8
                   U _gfortran_string_len_trim@@GFORTRAN_8
                   U _gfortran_string_trim@@GFORTRAN_8
                   U _gfortran_st_write_done@@GFORTRAN_8
                   U _gfortran_st_write@@GFORTRAN_8
                   ...
  </code></pre>
  <p>ldd model.cpython-38-x86_64-linux-gnu.so:</p>
  <pre><code>        linux-vdso.so.1 (0x00007ffc07da3000)
          libgfortran.so.5 =&gt; /usr/lib64/libgfortran.so.5 (0x00007fe5c0b33000)
          libc.so.6 =&gt; /usr/lib64/libc.so.6 (0x00007fe5c0929000)
          libquadmath.so.0 =&gt; /home/rbenedetti/miniconda3/envs/mais-soja/lib/libquadmath.so.0 (0x00007fe5c08ef000)
          libm.so.6 =&gt; /usr/lib64/libm.so.6 (0x00007fe5c0813000)
          libgcc_s.so.1 =&gt; /home/rbenedetti/miniconda3/envs/mais-soja/lib/libgcc_s.so.1 (0x00007fe5c07ff000)
          /lib64/ld-linux-x86-64.so.2 (0x00007fe5c0e37000)
  </code></pre>
  <p>python setup.py build_ext --inplace:</p>
  <pre><code>MAKEFILE OUT
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Utils.o src/model/Utils.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Logger.o src/model/Logger.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Benchmark.o src/model/Benchmark.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/coefficients.o src/model/coefficients.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Results.o src/model/Results.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Parameters.o src/model/Parameters.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/IO.o src/model/IO.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Parser.o src/model/Parser.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Simulation.o src/model/Simulation.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Instrumentalization.o src/model/Instrumentalization.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/API.o src/model/API.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Program.o src/model/Program.f90
  mkdir -p dist/release
  gfortran -I build/release -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o dist/release/model build/release/Utils.o build/release/Logger.o build/release/Benchmark.o build/release/coefficients.o build/release/Results.o build/release/Parameters.o build/release/IO.o build/release/Parser.o build/release/Simulation.o build/release/Instrumentalization.o build/release/API.o build/release/Program.o
  ln -fs dist/release/model release-link
  
  MAKEFILE ERR
  
  running build_ext
  building 'model' extension
  creating build/temp.linux-x86_64-3.8
  creating build/temp.linux-x86_64-3.8/src
  creating build/temp.linux-x86_64-3.8/src/cython
  gcc -pthread -B /home/rbenedetti/miniconda3/envs/mais-soja/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Isrc/cython -I/usr/local/include -I/home/rbenedetti/miniconda3/envs/mais-soja/include/python3.8 -c src/cython/model.c -o build/temp.linux-x86_64-3.8/src/cython/model.o -g -static -static-libgfortran
  In file included from src/cython/model.c:724:
  src/cython/API.h:28:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
     28 | extern void wrapper_reset();
        | ^~~~~~
  creating build/lib.linux-x86_64-3.8
  gcc -pthread -shared -B /home/rbenedetti/miniconda3/envs/mais-soja/compiler_compat -L/home/rbenedetti/miniconda3/envs/mais-soja/lib -Wl,-rpath=/home/rbenedetti/miniconda3/envs/mais-soja/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/src/cython/model.o -lgfortran -o build/lib.linux-x86_64-3.8/model.cpython-38-x86_64-linux-gnu.so build/release/Utils.o build/release/Logger.o build/release/Benchmark.o build/release/coefficients.o build/release/Results.o build/release/Parameters.o build/release/IO.o build/release/Parser.o build/release/Simulation.o build/release/Instrumentalization.o build/release/API.o
  copying build/lib.linux-x86_64-3.8/model.cpython-38-x86_64-linux-gnu.so -&gt; 
  </code></pre>
  <h2>Outside of conda env:</h2>
  <p>nm model.cpython-38-x86_64-linux-gnu.so --undefined:</p>
  <pre><code>                 w __cxa_finalize@GLIBC_2.2.5
                   U free@GLIBC_2.2.5
                   U _gfortran_adjustl
                   U _gfortran_compare_string
                   U _gfortran_concat_string
                   U _gfortran_exit_i4
                   U _gfortran_fdate_sub
                   U _gfortran_getarg_i4
                   U _gfortran_iargc
                   U _gfortran_select_string
                   U _gfortran_st_inquire
                   ...
  </code></pre>
  <p>ldd model.cpython-38-x86_64-linux-gnu.so:</p>
  <pre><code>        linux-vdso.so.1 (0x00007ffce5559000)
          libc.so.6 =&gt; /usr/lib64/libc.so.6 (0x00007f6457e74000)
          /lib64/ld-linux-x86-64.so.2 (0x00007f64580d2000)
  </code></pre>
  <p>python setup.py build_ext --inplace:</p>
  <pre><code>python setup.py build_ext --inplace
  MAKEFILE OUT
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Utils.o src/model/Utils.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Logger.o src/model/Logger.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Benchmark.o src/model/Benchmark.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Coefficients.o src/model/Coefficients.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Results.o src/model/Results.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Parameters.o src/model/Parameters.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/IO.o src/model/IO.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Parser.o src/model/Parser.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Simulation.o src/model/Simulation.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Instrumentalization.o src/model/Instrumentalization.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/API.o src/model/API.f90
  mkdir -p build/release
  gfortran -J build/release -c -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o build/release/Program.o src/model/Program.f90
  mkdir -p dist/release
  gfortran -I build/release -std=f2003 -fall-intrinsics -fPIC -cpp -static -static-libgfortran -Ofast -o dist/release/model build/release/Utils.o build/release/Logger.o build/release/Benchmark.o build/release/Coeficients.o build/release/Results.o build/release/Parameters.o build/release/IO.o build/release/Parser.o build/release/Simulation.o build/release/Instrumentalization.o build/release/API.o build/release/Program.o
  ln -fs dist/release/model release-link
  
  MAKEFILE ERR
  
  running build_ext
  building 'model' extension
  creating build/temp.linux-x86_64-3.10
  creating build/temp.linux-x86_64-3.10/src
  creating build/temp.linux-x86_64-3.10/src/cython
  gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Isrc/cython -I/usr/local/include -I/usr/include/python3.10 -c src/cython/model.c -o build/temp.linux-x86_64-3.10/src/cython/model.o -g -static -static-libgfortran
  creating build/lib.linux-x86_64-3.10
  gcc -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -g -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -g build/temp.linux-x86_64-3.10/src/cython/model.o -L/usr/lib64 -lgfortran -o build/lib.linux-x86_64-3.10/model.cpython-310-x86_64-linux-gnu.so build/release/Utils.o build/release/Logger.o build/release/Benchmark.o build/release/Coefficients.o build/release/Results.o build/release/Parameters.o build/release/IO.o build/release/Parser.o build/release/Simulation.o build/release/Instrumentalization.o build/release/API.o
  copying build/lib.linux-x86_64-3.10/model.cpython-310-x86_64-linux-gnu.so -&gt; 
  </code></pre>
  <p>Any idea why GCC refuse to link the needed libraries outside a conda environment? As you may expect, not linking gfortran results in undefined reference when importing the module in python.</p>
  <hr />
  <h2>Extra system info:</h2>
  <p>find /usr -name libgfortran*:</p>
  <pre><code>/usr/lib/gcc/x86_64-redhat-linux/11/32/libgfortran.a
  /usr/lib/gcc/x86_64-redhat-linux/11/32/libgfortran.so
  /usr/lib/gcc/x86_64-redhat-linux/11/libgfortran.a
  /usr/lib/gcc/x86_64-redhat-linux/11/libgfortran.so
  /usr/lib/gcc/x86_64-redhat-linux/11/libgfortran.spec
  /usr/lib/libgfortran.so.5
  /usr/lib/libgfortran.so.5.0.0
  /usr/lib/libgfortran.so
  /usr/lib/libgfortran.a
  /usr/lib64/python3.5/site-packages/scipy/.libs/libgfortran-ed201abd.so.3.0.0
  /usr/lib64/python3.5/site-packages/numpy/.libs/libgfortran-ed201abd.so.3.0.0
  /usr/lib64/libgfortran.so.1
  /usr/lib64/libgfortran.so.1.0.0
  /usr/lib64/libgfortran.so.5
  /usr/lib64/libgfortran.so.5.0.0
  ...
  </code></pre>