gpt4 book ai didi

c++ - g++ 编译不识别 '*' 使用 Armadillo 库进行矩阵乘法

转载 作者:太空宇宙 更新时间:2023-11-04 13:13:55 26 4
gpt4 key购买 nike

我在编译以下 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++ 编译时的错误:

Undefined symbols for architecture x86_64: "_wrapper_dgemm_", referenced from:

 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_", referenced from:

 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.o

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see >invocation)

当我用“+”、“%”等替换矩阵乘法“*”时,代码编译时没有任何提示。

提前致谢!

最佳答案

该错误是一个简单的链接器 错误,您可以通过正确构建来克服它。您究竟需要什么取决于您的系统/操作系统(并且已全部记录在案),但在我的 Linux 机器上这是可行的:

edd@max:/tmp$ g++ -o arma arma.cpp -larmadillo 
edd@max:/tmp$ ./arma
Mutliplying matrices A and B:
A * B = 1.0574 1.0356 1.5178
1.1368 1.3434 1.4919
0.7028 0.6516 1.0423

edd@max:/tmp$

此处 arma.cpp 是包含您的示例的文件。仅链接 libarmadillo.so 库就足够了,因为它链接到 LAPACK 和 BLAS 库。其他操作系统可能有不同的使用模式。

关于c++ - g++ 编译不识别 '*' 使用 Armadillo 库进行矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38400242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com