Using Armadillo in cling

Hi,

I’m trying to run Armadillo (arma.sourceforge.net) in root/cling. The following code:

#include <armadillo>
#include <iostream>

using namespace std;
using namespace arma;

int main() {

  mat A = mat(2,4);
  cout << A << endl;
  A.ones();
  cout << A << endl;
  A.randu();
  cout << A << endl;  

  return 0;
  
}

runs as expected when compiled as:

g++ test.cpp -larmadillo

when in cling/root I’m having issues however as it can’t seem to find symbols that are in libarmadillo.so (checked using nm). The following:

.L /usr/lib/libarmadillo.so

#include <armadillo>
#include <iostream>

using namespace std;
using namespace arma;

mat A = mat(2,4);
cout << A << endl;
A.ones();
cout << A << endl;
A.randu();
cout << A << endl;  

run interactively in the root/cling shell gives a missing symbol error for A.randu(). This method has to call into the runtime for the RNG code. It works fine up to that point. My guess is that the rest are defined in armadillo’s header files. I’m very new to using root/cling so any help would be much appreciated. I also tried using:

gSystem->Load("/usr/lib/libarmadillo.so")

but get the same results.

Many thanks,
Jason

Could you please try with R__LOAD_LIBRARY(libarmadillo) instead of .L? That should work.

Just to follow up for anyone else who might be interested. This code:

R__LOAD_LIBRARY(libarmadillo)

#define ARMA_DONT_USE_WRAPPER
#include <armadillo>
#include <iostream>

using namespace std;
using namespace arma;

mat A = mat(4,4);
cout << A << endl;
A.ones();
cout << A << endl;
A.randu();
cout << A << endl;
cout << A*A << endl; 

works correctly. The #define before the #include is the key bit to get the library to work. It will also work if you use .L /usr/lib/libarmadillo.so. That said, I much prefer R__LOAD_LIBRARY(libarmadillo) as it will then run as a script. Thank you amadio.

Jason

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.