You can also get prebuilt libraries from a number of places. Have a look at the site that you downloaded gfortran from, as this is more likely to be binary compatible.
If you are willing, it is recommended to use Windows-MSYS2. It provides a complete GFortran environment and OpenBLAS package, which is easy to obtain. This may require a little learning cost, but it is definitely simpler than installing GCC and the BLAS library separately. The following are the commands for installing the packages you need in the msystem:UCRT64 environment:
Now Iβd like to do the following program: lapack_example.f95
(I am writing text in Plato)
program lapack_example
implicit none
integer, parameter :: n = 3
double precision :: a(n,n), b(n)
integer :: ipiv(n), info
! Initialize matrix A and vector B
data a / 1.0d0, 2.0d0, 3.0d0, &
0.0d0, 4.0d0, 5.0d0, &
0.0d0, 0.0d0, 6.0d0 /
data b / 6.0d0, 15.0d0, 24.0d0 /
! Call LAPACK routine DGESV to solve A*x = b
call dgesv(n, 1, a, n, ipiv, b, n, info)
if (info == 0) then
print *, 'Solution:'
print *, b
else
print *, 'Error: DGESV failed with INFO = ', info
end if
end program lapack_example
now I go to cmd.exe:
C:\Users\chiara01\Documents>gfortran -o lapack_example lapack_example.f95
I always get error message that it cannot find DGESV:
β undefined reference to `dgesv_β ???
where liblapack.a and librefblas.a are Lapack and BLAS library files that you need to create or download. Note that the .f90 suffix is preferred over .f95, .f03 etc. since all modern compilers assume a .f90 source file uses free source form (not that it conforms to the Fortran 90 standard.)
my idea: I give source-file dgesv.f but also: dgetrf.f
** dgetrs.f**
** xerbla.f**
into that location on my PC, where lapack_example.f90 is stored.
If this is good idea(?) , please tell me the compilation/linking-order!
I can find files on: netlib.org/LAPACK
Thank you very much, Andreas
I am retired teacher, Math is not the problem, reading code in Fortran is easy too for me, but I never!! heard about linking with external programs
I was installing: Windows-MSYS2, but I am not successful in compiling and linking
@Andreas01, generally, the BLAS library is a whole, and its internal routines have relatively complex dependencies. Users often need to link the entire BLAS as a link library.
It seems that you lack some experience in using external link libraries. Generally, using build systems such as Make, CMake, Meson, Fpm, etc., will make it easier for you to handle complex code dependency issues.
As for the help documentation of using gfortran, you can obtain it from here.
If you have already installed gfortran and OpenBLAS in msystem:UCRT64 shell, then you can compile your code using following commands in the msystem:UCRT64 shell:
cd <path to work> # Switch to the working path
notepad lapack_example.f90 # Edit your code in Notepad
gfortran -c lapack_example.f90 -o lapack_example.f90.o # Compile the source code to the object binary file
gfortran -c lapack_example.f90.o -lopenblas -o lapack_example.exe # Link object binaries and openblas to generate executable programs
./lapack_example.exe # Run the executable