我刚开始使用库,我在使用lapack++和让它正常工作方面遇到了一些问题。我将解释到目前为止我所做的和尝试的事情。
首先,我安装了BLAS和LAPACK,一切都很顺利。我现在已经安装了LAPACK++版本2.5.2 (http://lapackpp.sourceforge.net/),所以我可以在C/C++中调用各种线性代数例程。在我进行配置、make和make install之后,它将所有的C/C++头文件放在/usr/local/include/lapackpp/中,其中一些是..
arch.h
bmd.h
gmf.h
lapackc.h
lautil.h
spdmd.h
ultgmd.h
bfd.h
...以及/usr/local/lib中的以下文件
liblapackpp.la
liblapackpp.so
liblapackpp.so.14
liblapackpp.so.14.2.0现在,如果我尝试使用g++编译简单的
#include <lapackpp/lapackpp.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}我得到了以下输出...
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我通过在引起问题的头文件中显式地写入头文件的位置解决了这个问题。
例如:我将#include替换为#include
这样做之后,我的代码编译得很好。
现在,如果我尝试编译代码
#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;
}通过键入
g++ test.cpp -o test -I usr/local/include/lapackpp我得到以下错误
/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(有关LaGenMatDouble的信息是here )
这表明我可能链接到了错误的库?
在谷歌了一下之后,我意识到我需要使用-I链接到头文件,通过-L链接到共享库,通过-llapackpp链接到库本身,所以我输入了
g++ test.cpp -o test -I usr/local/include/lapackpp -L usr/local/lib -llapackpp它编译了代码,现在当我通过输入./test来运行程序时,我看到了错误
./test: error while loading shared libraries: liblapackpp.so.14: cannot open shared object file: No such file or directory现在我很困惑。
我不确定这是否与问题有关,但当我键入
pkg-config lapackpp --libs我得到了
在pkg-config搜索路径中找不到程序包lapackpp。也许您应该将包含`lapackpp.pc的目录添加到PKG_CONFIG_PATH环境变量No package 'lapackpp‘中
lapack和blas也是如此。
我不知道该怎么办。如有任何帮助,将不胜感激,谢谢!
发布于 2012-05-23 19:34:38
链接很好,因为您告诉链接器库在哪里,但是执行失败了,因为加载程序不知道您的库的位置(您可以检查执行ldd yourapp,它显示您的应用程序需要的库)。
通常,您可以通过变量LD_LIBRARY_PATH告诉加载器库在哪里来解决这个问题,但它是一个粗糙的工具。另一种解决方案是直接在可执行文件中编码该指令,如here所述,或者使用开关-static静态链接您的应用程序
发布于 2012-12-18 17:53:42
如果您想要一个包装了LAPACK (和/或BLAS)的C++库,那么最好使用更现代的库,比如Armadillo。除了使用LAPACK作为求解器和矩阵分解的后端之外,它还使用表达式模板来加速操作。
https://stackoverflow.com/questions/10718800
复制相似问题