Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将gfortran链接到LAPACK和BLAS时出错_Fortran_Gfortran_Lapack_Blas - Fatal编程技术网

将gfortran链接到LAPACK和BLAS时出错

将gfortran链接到LAPACK和BLAS时出错,fortran,gfortran,lapack,blas,Fortran,Gfortran,Lapack,Blas,我已经在Ubuntu的Synaptic软件包管理器中安装了LAPACK和BLAS 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 当我尝试使用gfortran编译时,我收到以下错误消息 gfortran randomsys1.f90 -L

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

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
当我尝试使用
gfortran
编译时,我收到以下错误消息

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
lapack
blas
链接(请参阅)。提前感谢您指出使用
gfortran
编译
fortran
代码的正确方法

试试这个

gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas
我觉得你走得太远了

我用LAPACK eigensolver编写了一个程序,下面是我如何在自己的计算机上成功编译的。它被用来计算弹簧-质量系统的模态

gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack
这也适用于我的电脑

gfortran eigen.f90 -lblas -llapack
我只是想验证一下

PS,既然您知道了如何编译,我想您的程序中需要子程序init_random_seed(在“contains”之后,但在“end program”之前)。这是谷歌的。不知道这是否是你需要的,你的教授应该能在这里正确引导你

! 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

我也有同样的问题。我遵循了上面的建议 成功了。下面是我的工作示例批处理文件(必须执行它 在cmd窗口中):


非常感谢你!您已经正确地指出,
init\u random\u seed
子例程缺失。在包含了您提供的子例程之后,我可以使用命令
gfortran randomsys1.f90-lblas-llapack
编译它。代码似乎与现在的不匹配,可能有更新了?@Rajarshi,您能正式接受我的答案吗(答案左上角)?我的任务是获得更多积分!
! 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 -c for\kurs_evd.f90
gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
kurs_evd.exe