gfortran LAPACK“未定义的参考";错误 [英] gfortran LAPACK "undefined reference" error

查看:22
本文介绍了gfortran LAPACK“未定义的参考";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 说明,

sudo apt-get install liblapack-dev

这样我就可以找到/usr/lib/libblas/libblas.a/usr/lib/lapack/liblapack.a,然后在gfortran 与 randomsys1 示例,

thus I can find /usr/lib/libblas/libblas.a and /usr/lib/lapack/liblapack.a, and then tested it in gfortran with the randomsys1 example,

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

但我收到以下错误(dgesv 是 LAPACK 例程):

but I received the following errors (dgesv is a LAPACK routine):

/tmp/ccnzuuiY.o: In function `MAIN__':
randomsys1.f90:(.text+0xb): undefined reference to `init_random_seed_'
randomsys1.f90:(.text+0x3c2): undefined reference to `dgesv_'
collect2: ld returned 1 exit status

安装LAPACK有什么问题吗?非常感谢!

Is there anything wrong to install LAPACK? Thanks a lot!

推荐答案

参见gcc/gfortran 文档:

-library,-l 库

链接时搜索名为 library 的库.(将库作为单独参数的第二种选择仅适用于 POSIX合规性,不推荐.)

Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

在命令的哪个位置编写此选项会有所不同;链接器在它们被指定的顺序.因此,foo.o -lz bar.o"搜索库z"在文件 foo.o 之后但在 bar.o 之前.如果 bar.o 指的是函数‘z’,那些函数可能无法加载.

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

链接器搜索库的标准目录列表,该库实际上是一个名为 liblibrary.a 的文件.然后链接器使用这个文件,就好像它是按名称精确指定的一样.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

搜索的目录包括几个标准系统目录以及您使用 -L 指定的任何目录.

The directories searched include several standard system directories plus any that you specify with -L.

通常以这种方式找到的文件是库文件——其成员是目标文件的存档文件.链接器通过以下方式处理归档文件扫描它的成员,这些成员定义了迄今为止的符号被引用但未定义.但是如果找到的文件是普通的目标文件,它以通常的方式链接.唯一的使用 -l 选项和指定文件名之间的区别是that -l 用lib"和.a"包围库并搜索几个目录.

Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.

所以你必须先放 -L/directory/of/the/library 以便编译器知道包含你的库的目录,然后然后code>-llibrary 标志.

So you have to put first the -L/directory/of/the/library so the compiler is aware of the directory containing your library, and then the -llibrary flag.

这篇关于gfortran LAPACK“未定义的参考";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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