Problem with code signing

I have a Fortran program and I compiled it with gfortran, like what follows,

gfortran -mmacosx-version-min=10.14.3 -ffixed-line-length-none -c ../main_tools/thermal_ellipsoid.f90
gfortran -o thermal_ellipsoid thermal_ellipsoid.o

The compiled executable thermal_ellipsoid is working fine locally. However, when I tried to sign the executable using codesign, it was failing. Here follows is the command I used to sign the executable,

codesign -f --timestamp -o runtime -v --sign 'Developer ID Application: XXXXX' thermal_ellipsoid

and here is the error I got,

./thermal_ellipsoid
dyld[45718]: Library not loaded: /usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib
  Referenced from: <37A6CBC1-BFE9-31F0-B397-34A05BBA2B6C> /Users/y8z/Dev/RMCProfile/mac-gfortran/thermal_ellipsoid
  Reason: tried: '/usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib' (code signature in <CF6596E0-B4AA-3AD2-9620-74B6FC158924> '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib' (no such file), '/usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib' (code signature in <CF6596E0-B4AA-3AD2-9620-74B6FC158924> '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache), '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' (code signature in <CF6596E0-B4AA-3AD2-9620-74B6FC158924> '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' (no such file), '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' (code signature in <CF6596E0-B4AA-3AD2-9620-74B6FC158924> '/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/libgfortran.5.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)
[1]    45718 abort      ./thermal_ellipsoid

Is there anything wrong with my code signing?

The executable is trying to load some unsigned libraries from /usr/local/opt/, that can't be loaded because it was signed with the hardened runtime enabled. Maybe there is a way to do a static build with that library included? I never used gfortran, so I can't help more than this.

Problem with code signing
 
 
Q