如何将lapack和BLAS库链接到C ++代码 [英] How to Link lapack and BLAS library to C++ code
问题描述
以上是线性代数库.我正在使用armadillo,它类似于c ++包装器/框架,用于链接到fortran中的更多基本线性代数库.
The above are linear algebra libraries. i am using armadillo which is like a c++ wrapper/framework for linking to more basic linear algebra libraries in fortran.
我可以通过使用带有-I标志的gcc -c选项#include"armadillo"来轻松编译example.cpp.这将生成example.o,现在应该将其静态链接到liblapack_LINUX.a和libBLAS_linux.a
I can compile the example.cpp easily by having a #include "armadillo" using gcc -c option with the -I flag. This generates example.o which is now supposed to be linked to liblapack_LINUX.a and libBLAS_linux.a Statically
两者的位置:
liblapack_LINUX.a :-/home/nimish/HTMLProjects/WP2/lib/lapack/
libBLAS_linux.a :-/home/nimish/HTMLProjects/WP2/lib/blas
我发出以下命令:
gcc -o example.o -L../lib/blas -lblas_LINUX -L../lib/lapack -llapack_LINUX
或具有绝对路径的
nimish@ubuntu:~$ gcc -o example.o -L/home/nimish/HTMLProjects/WP2/lib/blas -lblas_LINUX -L/home/nimish/HTMLProjects/WP2/lib/lapack -llapack_LINUX
得到错误:
/usr/bin/ld: cannot find -lblas_LINUX
collect2: ld returned 1 exit status
但是这些库确实存在-
nimish@ubuntu:~$ find /home/nimish/HTMLProjects/WP2 -name liblapack_LINUX.a
/home/nimish/HTMLProjects/WP2/lib/lapack/liblapack_LINUX.a
nimish@ubuntu:~$ find /home/nimish/HTMLProjects/WP2 -name libblas_LINUX.a
/home/nimish/HTMLProjects/WP2/lib/BLAS/libblas_LINUX.a
我在做什么错?我对这种链接库业务以及gcc还是陌生的.
What am i doing wrong? I am somewhat new to this linking libraries business as well as gcc.
推荐答案
首先,您需要确保已使用(+ lapack)
first you need to ensure you have BLAS installed using(+lapack)
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install libblas-dev liblapack-dev
然后您可以在程序文件后使用-lblas进行链接.或者您可以使用制作文件.
then you can link using -lblas after your program files. or you can use a make file.
从我的角度来看,我更喜欢使用OpenBlas,您可以在makefile中使用以下内容.
from my side I prefer to use OpenBlas instead, you can use the following in a makefile.
- www.openblas.net ,获取tar.gz将其复制到您的目录中
- 提取它:tar -zxvf OpenBLAS-0.2.20.tar.gz
- 编译它:cd OpenBLAS-0.2.20做
- www.openblas.net, get the tar.gz copy it in your directory
- extract it : tar -zxvf OpenBLAS-0.2.20.tar.gz
- compile it : cd OpenBLAS-0.2.20 make
完成后,您应该拥有文件libopenblas.a,即openblas库
When it is done you should have the file libopenblas.a, the openblas library
- BLASLIB = OpenBLAS/libopenblas.a -lpthread
这篇关于如何将lapack和BLAS库链接到C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!