Software development in LINUX/UNIX
In general libraries, modules and programs should all be compiled with the same compiler and the same compile version.
Using shared libraries at non-default location
The compiler needs to know where to find the header files (e.g. netcdf.inc) and/or the module files (netcdf.mod):
gfortran -I/path/to/header/file source.f90
Some Fortran 77 libraries (such as LAPACK and BLAS) do not use header files. Assuming there is a library libname.so under /path/to/lib, the options during linking are:
gfortran -o executable source.o -L/path/to/lib -lname
If the library name, depends on other libraries (for example LAPACK depends on BLAS), the other libraries have to added in the order of dependence (e.g. "-llapack -lblas" but not "-lblas -llapack").
At run-time the environment variable LD_LIBRARY_PATH need to include the path to /path/to/lib:
export LD_LIBRARY_PATH="/path/to/lib:$LD_LIBRARY_PATH" ./executable
Modifying the variable LD_LIBRARY_PATH is not necessary if during linking one defines the "run-path":
gfortran -o executable source.o -L/path/to/lib -lname -Wl,-R/path/to/lib
An example for OAK can be found at nic3:/u/abarth/Assim/OAK/config.mk. If LD_LIBRARY_PATH or the "run-path" is not adapted, one gets an error like this:
error while loading shared libraries: libname.so: cannot open shared object file: No such file or directory
Debugging run-time errors:
- recompile your code with "-g -C"
- enable cores
ulimit -c 10000000
This allows core with a maximum size of 10M.
- run your program
- run the debugger
gdb <executable> core
inside the debugger you can use the commands such as "where", "print", "up",... See man gdb.
gdb -p pid#
allows one to see what a program is doing while it executes.
Note if you use a different compiler (e.g. ifort, pgf90) it might be preferable to use a different debugger (e.g. idb, pgdbg)
A list with debugging options depending on compiler: http://fortranwiki.org/fortran/show/Debugging+tools