[英]Error information in the compiling of c++ with armadillo library
犰狳图书馆的初学者,有两个问题。 第一个问题是关于犰狳和c ++的链接。 我按照软件包中的说明安装了armadillo,并且位置是/usr/include/
,我可以成功运行代码:
#include <iostream>
#include "/usr/include/armadillo"
using namespace std;
int main()
{
arma::mat a = arma::randu<arma::mat>(3, 3);
cout << a << endl;
return 0;
}
但是如果我想定义一个函数,例如矩阵的逆函数(可以从库中调用一个函数,但是我只想做一个测试)。
#include <iostream>
#include "/usr/include/armadillo"
using namespace std;
arma::mat Inverse( arma::mat A){
return arma::inv(A);
}
int main()
{
arma::mat a = arma::randu<arma::mat>(3, 3);
arma::mat inv_a = Inverse(a);
cout << inv_a << endl;
return 0;
}
然后程序失败,并显示三个错误消息。
Undefined symbols for architecture x86_64:
"_wrapper_dgetrf_", referenced from:
void arma::lapack::getrf<double>(int*, int*, double*, int*, int*, int*) in main.o
"_wrapper_dgetri_", referenced from:
void arma::lapack::getri<double>(int*, double*, int*, int*, double*, int*, int*) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我通过Google进行了检查,并尝试了一些建议,例如: “在其他MAC OS X链接器中,我必须放置“ -01 -larmadillo”,并且必须停用共享库设置!” ,说实话,由于我不熟悉Xcode,我找不到miscellaneous
选项并deactivate the shared library settings
。 然后我接着安装MacPorts,并将该库安装到文件夹/usr/local/include/
,然后再次尝试,第一个程序还可以,但是第二个程序仍然有三个错误,有人可以帮我吗?
第二个问题是当我在同一程序中使用armadillo时使用lapack,因为我知道armadillo基于lapack,那么如果我声明了armadillo
库,是否需要声明lapacke.h
。 我为什么要问这个问题是当我声明RcppArmadillo
和lapacke.h
,存在错误:
This file includes at least one deprecated or antiquated header. Please consider using of the 32 header found in section 17.4.1.2 of the C++ standard. Example include substituting the <X> header for the <X.h> hear for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. [-W#warnings]
Line 11763 conflicting type for 'cgetrf'
Line 11765 conflicting type for 'zgetrg_'
...
我遇到了同样的问题,但最终我解决了。 我没有出于自己的目的安装armadillo,但提供了包含目录和库目录的绝对路径。 另外,在自述文件中有一条注释,即如果您使用的是Mac,则应使用“ -framework Accelerate”之类的Accelerate框架。 因此,完成此操作后,所有链接器错误均消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.