将gfortran链接到LAPACK和BLAS时出错 [英] Error in linking gfortran to LAPACK and BLAS

查看:219
本文介绍了将gfortran链接到LAPACK和BLAS时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Ubuntu的Synaptic软件包管理器中安装了LAPACK和BLAS.

I have installed LAPACK and BLAS from Synaptic package manager in Ubuntu.

whereis libblas
libblas: /usr/lib/libblas.so /usr/lib/libblas.a /usr/lib/libblas

whereis liblapack
liblapack: /usr/lib/liblapack.a /usr/lib/liblapack.so

当我尝试编译 randomsys1示例使用gfortran会收到以下错误消息.

When I try to compile the randomsys1 example with gfortran I get the following error messages.

gfortran randomsys1.f90 -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas
/tmp/cclwtifh.o: In function `MAIN__':
randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
collect2: error: ld returned 1 exit status

gfortran randomsys1.f90 -llapack -lblas
/tmp/ccB1isEC.o: In function `MAIN__':
randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
collect2: error: ld returned 1 exit status

据我了解,这是将gfortranlapackblas链接的推荐方法(请参考).在此先感谢您指出使用gfortran编译fortran代码的正确方法.

As per my understanding, it is the recommended way to link gfortran with lapack and blas (kindly refer to gfortran LAPACK "undefined reference" error). Thanks in advance for pointing out the correct way to compile the fortran code using gfortran.

推荐答案

尝试一下

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

我认为您到一个目录太远了

I think you went one directory too far

我使用LAPACK eigensolver编写了一个程序,这就是我在自己的计算机上成功编译该程序的方式.它用于计算弹簧质量系统的模式.

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,既然您知道如何编译,那么我认为您需要程序中的子例程init_random_seed(在包含"之后但在结束程序"之前).这个是谷歌的.不知道您是否需要它,您的教授应该能够在这里正确引导您.

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

这篇关于将gfortran链接到LAPACK和BLAS时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆