静态链接 LAPACK [英] Statically linking against LAPACK

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

问题描述

我正在尝试发布一些软件,目前正在编写构建过程的脚本.我被困在我从未想过的事情上,在 x86_64 linux 上静态链接 LAPACK.在配置期间 AC_SEARCH_LIB([main],[lapack]) 工作,但 lapack 单元的编译不起作用,例如 undefiend reference to 'dsyev_' --no lapack/blas 例程未被注意到.

I'm attempting to do a release of some software and am currently working through a script for the build process. I'm stuck on something I never thought I would be, statically linking LAPACK on x86_64 linux. During configuration AC_SEARCH_LIB([main],[lapack]) works, but compilation of the lapack units do not work, for example undefiend reference to 'dsyev_' --no lapack/blas routine goes unnoticed.

我已经确认我已经安装了这些库,甚至使用适当的选项自己编译了它们,以使它们成为静态的并获得相同的结果.

I've confirmed I have the libraries installed and even compiled them myself with the appropriate options to make them static with the same results.

这是我几年前第一次使用 LAPACK 时使用的示例,它可以动态工作,但不能静态工作:http://pastebin.com/cMm3wcwF

Here is an example I had used in my first experience with LAPACK a few years ago that works dynamically, but not statically: http://pastebin.com/cMm3wcwF

我用来编译的两种方法如下,

The two methods I'm using to compile are the following,

gcc -llapack -o eigen eigen.c
gcc -static -llapack -o eigen eigen.c

推荐答案

您的链接顺序错误.在需要它们的代码之后链接库,而不是之前.像这样:

Your linking order is wrong. Link libraries after the code that requires them, not before. Like this:

gcc -o eigen eigen.c -llapack 
gcc -static -o eigen eigen.c -llapack

这应该可以解决链接问题.

That should resolve the linkage problems.

为了回答后面的问题为什么这样有效,GNU ld 文档这样说:

To answer the subsequent question why this works, the GNU ld documentation say this:

在命令的哪个位置编写此选项会有所不同;这链接器按顺序搜索和处理库和目标文件它们是指定的.因此,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 libraryz' after file foo.o but before bar.o. If bar.o refers to functions in `z', those functions may not be loaded.

........

通常以这种方式找到的文件是库文件——存档文件其成员是目标文件.链接器通过以下方式处理归档文件扫描它的成员,这些成员定义了迄今为止的符号被引用但未定义.但是如果找到的文件是普通的目标文件,它以通常的方式链接.

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.

即.链接器将通过文件查找未解析的符号,并按照您提供的顺序(即从左到右")跟踪文件.如果在读取文件时尚未指定依赖项,则链接器将无法满足该依赖项.链接列表中的每个对象只被解析一次.

ie. the linker is going to make one pass through a file looking for unresolved symbols, and it follows files in the order you provide them (ie. "left to right"). If you have not yet specified a dependency when a file is read, the linker will not be able to satisfy the dependency. Every object in the link list is parsed only once.

还要注意,如果在链接共享库或目标文件时检测到循环依赖关系,GNU ld 可以进行重新排序.但是静态库只解析一次未知符号.

Note also that GNU ld can do reordering in cases where circular dependencies are detected when linking shared libraries or object files. But static libraries are only parsed for unknown symbols once.

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

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