solving a system of linear equation using Armadillo library in c++

I am trying to use armadillo library to solve a system of linear equation in c++. as shown in the code I can define the sparse matrix (A) and vector b with out any errors. I want to solve A.x=b. I used the spsolve(A, b) function to solve it, but I got the errors when I add this line: vec x = spsolve(A, b);

should I add anything else?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <armadillo>


using namespace std;
using namespace arma;

int main()
{
  sp_mat A(4,4);   

  // fill with direct element access
  A(0,0) = 1.0;
  A(0,1) = 2.0;
  A(1,1) = 3.0;
  A(2,2) = 4.0;
  A(2,3) = 5.0;
  A(3,2) = 6.0;
  A(3,3) = 7.0;  // etc


  vec b(4); // ... fill b here ...
  b(0)=5;
  b(1)=2;
  b(2)=1;
  b(3)=3;

  vec x = spsolve(A, b);  // solve one system
  
  return 0;
}
Last edited on
Phrases like "doesn't work" or "gives errors" convey almost no information. Tell us the errors. Are we supposed to just know what the errors are?
when I add x = spsolve(A, b); I got lost of errors and some are listed as below. I read somewhere else that I should add #include <RcppArmadillo.h> but I do not how I can do.

1>Source.obj : error LNK2028: unresolved token (0A000A62) "extern "C" void * __cdecl superlu_malloc(unsigned int)" (?superlu_malloc@@$$J0YAPAXI@Z) referenced in function "void * __cdecl arma::superlu::malloc(unsigned int)" (?malloc@superlu@arma@@$$FYAPAXI@Z)


1>Source.obj : error LNK2028: unresolved token (0A000A60) "extern "C" void __cdecl cgssv(struct arma::superlu::superlu_options_t *,struct arma::superlu::SuperMatrix *,int *,int *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperLUStat_t *,int *)" (?cgssv@@$$J0YAXPAUsuperlu_options_t@superlu@arma@@PAUSuperMatrix@23@PAH2111PAUSuperLUStat_t@23@2@Z) referenced in function "void __cdecl arma::superlu::gssv<double>(struct arma::superlu::superlu_options_t *,struct arma::superlu::SuperMatrix *,int *,int *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperMatrix *,struct arma::superlu::SuperLUStat_t *,int *)" (??$gssv@N@superlu@arma@@$$FYAXPAUsuperlu_options_t@01@PAUSuperMatrix@01@PAH2111PAUSuperLUStat_t@01@2@Z)
Those are linker errors, not compiler ones, so changing #include statements won't fix it.

Do you have the Armadillo libraries installed?

Have you told your linker to link against the Armadillo libraries?

Does your linker path include the directory containing them?
I have included path for armadillo file in include directory. so #include <armadillo> works. should I do any thins else?
I think the problem is due RcppArmadillo.h, maybe, is there any one can tell what should I do in order to use armadillo library to use spsolve(A, b);.
Last edited on
I have included path for armadillo file in include directory. so #include <armadillo> works.

Yes, it does. And I've already told you that this is a linker issue, not a compiler one, so it's not about where header files are.

I think the problem is due RcppArmadillo.h

Why do you think the header file is responsible for linker errors?

Do you have the Armadillo libraries installed?

Have you told your linker to link against the Armadillo libraries?

Does your linker path include the directory containing those libraries?
Last edited on
Topic archived. No new replies allowed.