I have a small fortran code in tmp0.f
subroutine POWERTWO (n, nsquared)
integer, intent(in) :: n
integer, intent(out) :: nsquared
nsquared = n*n
return
end subroutine POWERTWO
that I compile into a dynamic library with :
gfortran-5.2.0 -m32 -dynamiclib ./tmp0.f -o ./tmp0.so -shared
where my gfortran
was build with gcc 5.2.0 and configured as follows :
Using built-in specs.
COLLECT_GCC=gfortran-5.2.0
COLLECT_LTO_WRAPPER=/usr/local/lvm/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr/local/lvm/gcc-5.2.0 --enable-checking=release --with-gmp=/usr/local/lvm/gmp-6.0.0 --with-mpfr=/usr/local/lvm/mpfr-3.1.2 --with-mpc=/usr/local/lvm/mpc-1.0.3 --enable-languages=c,c++,fortran,objc,obj-c++ --with-isl=/usr/local/lvm/isl-0.14 --with-cloog=/usr/local/lvm/cloog-0.18.4 --program-suffix=-5.2.0
Thread model: posix
gcc version 5.2.0 (GCC)
Under OS X 10.10.5 the compilation produced (with no warning) the wanted dynamic library tmp0.dylib, but under ubuntu (15-05) I got the following warnings :
f951: Warning: unrecognized gcc debugging option: y
f951: Warning: unrecognized gcc debugging option: n
f951: Warning: unrecognized gcc debugging option: m
f951: Warning: unrecognized gcc debugging option: i
f951: Warning: unrecognized gcc debugging option: c
f951: Warning: unrecognized gcc debugging option: l
f951: Warning: unrecognized gcc debugging option: i
f951: Warning: unrecognized gcc debugging option: b
and the compilation produced, in addition to the dynamic library tmp0.so, a bunch of files :
-rw-rw-r-- 1 XXX XXX 4679 août 25 19:12 tmp0.f.192r.expand
-rw-rw-r-- 1 XXX XXX 1601 août 25 19:12 tmp0.f.193r.vregs
-rw-rw-r-- 1 XXX XXX 1602 août 25 19:12 tmp0.f.194r.into_cfglayout
-rw-rw-r-- 1 XXX XXX 3398 août 25 19:12 tmp0.f.195r.jump
-rw-rw-r-- 1 XXX XXX 1570 août 25 19:12 tmp0.f.207r.reginfo
-rw-rw-r-- 1 XXX XXX 1634 août 25 19:12 tmp0.f.225r.outof_cfglayout
-rw-rw-r-- 1 XXX XXX 1601 août 25 19:12 tmp0.f.226r.split1
-rw-rw-r-- 1 XXX XXX 2980 août 25 19:12 tmp0.f.228r.dfinit
-rw-rw-r-- 1 XXX XXX 3062 août 25 19:12 tmp0.f.229r.mode_sw
-rw-rw-r-- 1 XXX XXX 2980 août 25 19:12 tmp0.f.230r.asmcons
-rw-rw-r-- 1 XXX XXX 6631 août 25 19:12 tmp0.f.234r.ira
-rw-rw-r-- 1 XXX XXX 5581 août 25 19:12 tmp0.f.235r.reload
-rw-rw-r-- 1 XXX XXX 3299 août 25 19:12 tmp0.f.238r.split2
-rw-rw-r-- 1 XXX XXX 4347 août 25 19:12 tmp0.f.242r.pro_and_epilogue
-rw-rw-r-- 1 XXX XXX 3957 août 25 19:12 tmp0.f.245r.jump2
-rw-rw-r-- 1 XXX XXX 4007 août 25 19:12 tmp0.f.258r.stack
-rw-rw-r-- 1 XXX XXX 3925 août 25 19:12 tmp0.f.259r.alignments
-rw-rw-r-- 1 XXX XXX 3513 août 25 19:12 tmp0.f.261r.mach
-rw-rw-r-- 1 XXX XXX 3513 août 25 19:12 tmp0.f.262r.barriers
-rw-rw-r-- 1 XXX XXX 3578 août 25 19:12 tmp0.f.266r.shorten
-rw-rw-r-- 1 XXX XXX 3578 août 25 19:12 tmp0.f.267r.nothrow
-rw-rw-r-- 1 XXX XXX 4216 août 25 19:12 tmp0.f.268r.dwarf2
-rw-rw-r-- 1 XXX XXX 3578 août 25 19:12 tmp0.f.269r.final
-rw-rw-r-- 1 XXX XXX 2387 août 25 19:12 tmp0.f.270r.dfinish
What are these files, and can I avoid their production with some nice option passed to gfortran
?
Dynamic libraries (.dylib) are for your mac. On Linux, we use shared libraries (.so
) and your compile command should omit the -dynamiclib
, which your warning told you was not understood. I would also drop the -m32
unless you have a specific need for 32 bit code.
gfortran-5.2.0 -fPIC -shared ./tmp0.f -o ./tmp0.so
Will build your library properly. If you keep it in your build directory you'll also need to let the dynamic linker where it is, either by using the LD_LIBRARY_PATH
environment variable or using the -rpath
linker option to the eventual binary you link this to, to encode the library path into the executable.
That mess of files you wound up with are from the interpretation of -dynamic
by gcc. It interpreted the it as -da
(and warned you about not understanding the rest). The -d
option causes GCC to emit debugging dumps during compliation and the a
says to emit all of them. You can delete them all and they won't be output with the command line given above.