Trouble Linking Lapack

Error in linking gfortran to LAPACK and BLAS

Give this a try

gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas

I think you went one directory too far

I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.

gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack

This also works on my computer

gfortran eigen.f90 -lblas -llapack

I just tried both to verify.

PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.

! Initialize the random number generator using current time,
! so a new sequence of random numbers is generated each
! execution time.

! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

SUBROUTINE init_random_seed()
INTEGER :: i, n, clock
INTEGER, DIMENSION(:), ALLOCATABLE :: seed

CALL RANDOM_SEED(size = n)
ALLOCATE(seed(n))

CALL SYSTEM_CLOCK(COUNT=clock)

seed = clock + 37 * (/ (i - 1, i = 1, n) /)
CALL RANDOM_SEED(PUT = seed)

print *, "Using random seed = ", seed
print *, " "

DEALLOCATE(seed)
END SUBROUTINE

LAPACKE C++ linking error. Unable to find function

I am compiling with: g++ -lblas -llapack -llapacke -I /usr/include main.cpp

That command line is wrong. Do this instead:

g++ main.cpp -llapacke -llapack -lblas

To understand why the order of sources and libraries matters, read this.

Problems in linking LAPACK with Code:Blocks GNU fortran compiler Ubuntu 14.04

Where it says "Link libraries", where you currently have /usr/lib/lapack/liblapack.so, you enter just lapack and blas.

Where it says "Other linker options:", and you have -llapack and -lblas, you leave it empty. If that fails, you might add -L"usr/lib/lapack" there, but you probably don't need to.

If you look at the "Build log" tab at the bottom, it should tell you amongst other things the gfortran command that it has executed.

Linking error with LAPACK under cygwin

Supposing that you have installed BLAS and LAPACK libraries correctly and the system can locate them, then you just have to change the order in the compile command.

$ g++ main.cpp -llapack -lblas

The compiler should know which functions of main.cpp should look into the libraries before declare them.



Related Topics



Leave a reply



Submit