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

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

问题描述

我通过遵循指令在Ubuntu上安装了LAPACK >,

  sudo apt-get install liblapack-dev 
/usr/lib/libblas/libblas.a 和 / usr / lib / lapack / liblapack.a ,然后在 gfortran 中用 randomsys1 示例

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

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

  /tmp/ccnzuuiY.o:在函数MAIN__中:
randomsys1。 f90 :(。text + 0xb):未定义的引用'init_random_seed_'
r andomsys1.f90 :(。text + 0x3c2):对`dgesv_'的未定义引用
collect2:ld返回1退出状态

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

解决方案

请参阅 gcc / gfortran文档


- llibrary
-l library



链接。 (另一个与库作为单独参数的替代方案仅适用于POSIX
合规性,不建议使用。)



它在命令中的位置有所不同写这个选项;链接器按照它们指定的
顺序搜索和处理库和对象文件。因此,'foo.o -lz bar.o'在文件foo.o之后但在bar.o之前搜索库'z'
。如果bar.o指向
'z'中的函数,那么这些函数可能不会被加载。


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



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

通常,以这种方式找到的文件是库文件 - 其成员是对象文件的归档文件。链接器通过
扫描存档文件来处理定义符号的成员,该符号迄今为止引用了
但未定义。但是,如果找到的文件是一个
的普通对象文件,它将以通常的方式链接。使用-l选项和指定文件名称之间唯一的
差异是
,-l使用'lib'和'.a'围绕库并搜索多个
目录。


所以你必须先把 -L / directory / of / the / library 放到编译器知道包含你的库的目录,然后然后是 -llibrary 标志。


I installed LAPACK on Ubuntu by following the instruction,

sudo apt-get install liblapack-dev

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

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

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

解决方案

See the gcc/gfortran documentation:

-llibrary, -l library

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.)

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.

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.

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

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.

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天全站免登陆