简体   繁体   English

尝试安装和使用LAPACK ++,加载共享库时出现问题

[英]Trying to install and use LAPACK++, problems with loading shared libraries

I am new to using libraries and I am having some trouble with lapack++ and getting it to work. 我是使用库的新手,但是在使用lapack ++时遇到了一些麻烦,并且使其无法正常工作。 I will explain what I have done and tried so far. 我将解释我到目前为止所做的和尝试过的。

First I installed BLAS and LAPACK and that went fine. 首先,我安装了BLAS和LAPACK,一切正常。 I now have installed LAPACK++ version 2.5.2 (http://lapackpp.sourceforge.net/) so I can call various linear algebra routines in C/C++. 我现在已经安装了LAPACK ++版本2.5.2(http://lapackpp.sourceforge.net/),因此我可以在C / C ++中调用各种线性代数例程。 After I configure, make and then make install it places all the C/C++ header files in /usr/local/include/lapackpp/ some of which are.. 配置完后,进行make然后进行安装,它将所有C / C ++头文件放在/ usr / local / include / lapackpp /中,其中一些是..

arch.h
bmd.h 
gmf.h    
lapackc.h 
lautil.h     
spdmd.h 
ultgmd.h
bfd.h
...

and also the following files in /usr/local/lib 以及/ usr / local / lib中的以下文件

liblapackpp.la
liblapackpp.so
liblapackpp.so.14
liblapackpp.so.14.2.0

Now if I try to compile using g++ the simple code of 现在,如果我尝试使用g ++进行编译,则

#include <lapackpp/lapackpp.h>
using namespace std;

int main(int argc, char** argv) {
return 0;
}

I get the following output... 我得到以下输出...

In file included from /usr/local/include/lapackpp/lapackc.h:14,
from /usr/local/include/lapackpp/lapack.h:10,
from /usr/local/include/lapackpp/lapackpp.h:16,
from test.cpp:1:
/usr/local/include/lapackpp/lacomplex.h:45:23: error: laversion.h: No such file or directory
/usr/local/include/lapackpp/lacomplex.h:48:17: error: f2c.h: No such file or directory
In file included from /usr/local/include/lapackpp/lapackpp.h:47,
from test.cpp:1:
/usr/local/include/lapackpp/latmpl.h:36:22: error: lafnames.h: No such file or directory

I solved this problem by writing the location of the header file explicitly in the header file that was causing trouble. 我通过在引起麻烦的头文件中显式写入头文件的位置来解决此问题。

Eg. 例如。 I replaced #include with #include 我将#include替换为#include

After doing this my code compiles fine. 完成之后,我的代码可以正常编译。

Now if I try to compile the code 现在,如果我尝试编译代码

#include <cstdlib>
#include <iostream>
#include <lapackpp/lapackpp.h>

using namespace std;

int main(int argc, char** argv) {

LaGenMatDouble A(5,5);
cout << "This is a test." << endl;

return 0;
}

by typing 通过键入

g++ test.cpp -o test -I usr/local/include/lapackpp

I get the following errors 我收到以下错误

/tmp/ccAq6nkP.o: In function `main':
test.cpp:(.text+0x22): undefined reference to `LaGenMatDouble::LaGenMatDouble(int, int)'
test.cpp:(.text+0x4f): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
test.cpp:(.text+0x67): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
collect2: ld returned 1 exit status

(Info on LaGenMatDouble is here ) (有关LaGenMatDouble的信息在此处

which suggests I may be linking to the library wrong? 这表明我可能链接到库错误?

After some googling I realised that I needed to link to the header files using -I and the shared library by -L and the library itself by -llapackpp, so then I typed 经过一番谷歌搜索后,我意识到我需要使用-I链接到头文件,并通过-L链接到共享库,并通过-llapackpp链接到库本身,因此我键入了

g++ test.cpp -o test -I usr/local/include/lapackpp -L usr/local/lib -llapackpp

which compiled the code, now when I ran the program by typing ./test I go the error 编译了代码,现在当我输入./test来运行程序时,出现了错误

./test: error while loading shared libraries: liblapackpp.so.14: cannot open shared object file: No such file or directory

and now I am confused. 现在我很困惑。

I am unsure if this has anything to do with the problem but when I type 我不确定这是否与问题有关,但是当我键入时

pkg-config lapackpp --libs

I get 我懂了

Package lapackpp was not found in the pkg-config search path. 在pkg-config搜索路径中找不到软件包lapackpp。 Perhaps you should add the directory containing `lapackpp.pc' to the PKG_CONFIG_PATH environment variable No package 'lapackpp' found 也许您应该将包含“ lapackpp.pc”的目录添加到PKG_CONFIG_PATH环境变量中,但找不到软件包“ lapackpp”

The same happens for lapack and blas too. lapack和blas也是如此。

I am unsure what to do. 我不确定该怎么办。 Any help would be very much appreciated, thanks! 任何帮助将不胜感激,谢谢!

Linking goes fine because you tell to the linker where the library is, but execution failed because the loader doesn't know anything about the location of your libraries (you can check that performing ldd yourapp , which shows the library needed by your application). 链接可以正常进行,因为您将链接库告诉链接器,但执行失败是因为加载程序对库的位置一无所知(您可以检查是否执行了ldd yourapp ,它显示了应用程序所需的库)。

Usually, you can solve that by telling to the loader where the library is through the variable LD_LIBRARY_PATH , but it is a crude tool. 通常,您可以通过变量LD_LIBRARY_PATH告诉加载器库在哪里来解决该问题,但这是一个粗略的工具。 A different solution is to encode that instruction directly in the executable, as described here , or simply to link statically your application using the switch -static 一种不同的解决方案是该指令直接编码在可执行,如所描述的在这里 ,或者简单地使用该开关应用程序静态链接-static

If you're after a C++ library that wraps LAPACK (and/or BLAS), you might be better off using a more modern library such as Armadillo . 如果您使用的是包装LAPACK(和/或BLAS)的C ++库,那么最好使用更现代的库(例如Armadillo) Besides using LAPACK as a backend for solvers and matrix factorizations, it uses expression templates to speed up operations. 除了使用LAPACK作为求解器和矩阵分解的后端外,它还使用表达式模板来加快操作速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM