Armadillo + BLAS + LAPACK:链接错误?

8
当我试图编译Armadillo 2.4.2附带的example1.cpp时,我一直收到以下链接错误:
/tmp/ccbnLbA0.o: In function `double arma::blas::dot<double>(unsigned int, double const*, double const*)':
main.cpp:(.text._ZN4arma4blas3dotIdEET_jPKS2_S4_[double arma::blas::dot<double>(unsigned int, double const*, double const*)]+0x3b): undefined reference to `wrapper_ddot_'
/tmp/ccbnLbA0.o: In function `void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
main.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)]+0x68): undefined reference to `wrapper_dgemv_'
/tmp/ccbnLbA0.o: In function `void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
main.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)]+0x7a): undefined reference to `wrapper_dgemm_'
collect2: ld returned 1 exit status

有人能帮忙吗?我手动安装了以下软件:

  • BLAS的最新版本
  • lapack-3.4.0
  • boost-1.48.0
  • ATLAS的最新版本

我在MacBook Pro 7,1型号上使用Ubuntu 11.04操作系统。


2
看起来你的Armadillo没有正确配置,或者编译字符串中没有提到所需的库。你能展示一下如何编译example1.cpp吗? - osgx
3个回答

17

非常感谢 osgx!在阅读了他的评论后,我仔细再次查看了 README 文件!原来我没有在命令中加上“-O1 -larmadillo”!

以下是让它工作的命令:

g++ example1.cpp -o example1 -O1 -larmadillo

我知道这是个愚蠢的错误……但这提醒我们阅读README有多么重要。

README还提到:

如果出现链接错误,或者手动安装了Armadillo并且指定了LAPACK和BLAS可用,您需要显式地链接LAPACK和BLAS(或它们的等效物),例如:

g++ example1.cpp -o example1 -O1 -llapack -lblas

我不必包含“-llapack -lblas”,但也许这会帮助其他遇到类似问题的人。


这正是我一直在寻找的!只需链接 LAPACK 和 BLAS。我也有过不读 README 的罪行,所以不要感到难过。我正在进行交叉编译,并且遇到了对我的 LAPACK 和 BLAS 的未定义引用:'cgemv_'、'sdot_'等等。 - Matt

1

我刚刚通过比较之前编译成功的代码和本帖中出现的问题,发现了一个奇怪的事情,强调了gnu cc的参与(我不是专家):在我的机器上,编译成功取决于给gcc/g++传递参数的顺序,其中 g++ infile -o outfile -libarmadillo ... 成功了,但是 g++ -libarmadillo infile -o outfile ... 没有成功,出现了几乎相同的错误。


1

截至版本5.0.0(早期版本可能也适用)

实际上,您需要使用-larmadillo,在Fedora 21-llapack-lopenblas不再是必需的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接