【发布时间】:2016-07-15 15:46:16
【问题描述】:
我在编译以下 C++ 代码时遇到错误:
# include <iostream>
# include <armadillo>
using namespace arma;
using namespace std;
int main() {
mat A;
mat B;
mat C;
// Populating the matrices with random numbers
A.randu(3,3);
B.randu(3,3);
// Matrix multiplication
C = A * B;
cout << "Mutliplying matrices A and B:" << endl;
cout << "A * B = " << C << endl;
return 0;
}
这是我使用 g++ 编译时的错误:
架构 x86_64 的未定义符号: “_wrapper_dgemm_”,引用自:
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*) in >armadillo_playground-aa3649.o“_wrapper_dgemv_”,引用自:
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*) in armadillo_playground-aa3649.old:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看 >invocation)
当我将矩阵乘法 '*' 替换为 '+'、'%' 等时,代码编译成功。
提前致谢!
【问题讨论】:
-
看起来
*运算符的定义在源文件中,而您没有将库链接到其中? -
糟糕,我不知道库中的链接。但是,现在我遇到了以下错误:dyld:未加载库:/usr/local/opt/gcc/lib/gcc/6/libgfortran.3.dylib 引用自:/usr/local/opt/arpack/libexec /lib/libarpack.2.dylib 原因:找不到图像 Trace/BPT 陷阱:5
-
看来我需要更多的挖掘;这是我第一次使用外部库,我对 Xcode 不熟悉。我正在做的项目是将 C++ 链接到一些 R 代码中以完成机器学习任务。
-
@ToddYoung - 为什么不只使用RcppArmadillo,这一切都由您负责?