1

I'm trying to cross-compile (from ix86 to ARM) a code on the Eclipse IDE using the armadillo library.

I'm using the arm-linux-gnueabihf compiler from linaro.org. I already set up everything on Eclipse and can sucessfully cross compile c++ code.

After following this tutorial I could generate the liblapack.a, libf2c.a and liblas.a cross compiled libraries.

I think I correctly linked on Eclipse:

Cross G++ Linker -> Libraries ->

Libraries (-l)

lapack

f2c

blas

Library Search Path (-L)

Added the path to liblapack.a, libf2c.a and liblas.a files.

I can run simples code like the following without any problem. I think it's because simple programs like this don't need the cross compiled libraries, just the armadillo.

#include <armadillo>
#include <iostream>

using namespace std;
using namespace arma;
int main() {

mat A = randu(4,4);
cout << "A:\n" << A << "\n";
return 0;
}

But, when I try to compile my code with matrices multiplications or any other function that uses functionalities from the cross-compiled libraries, like this one:

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

using namespace std;
using namespace arma;
int main() {

mat A = randu(4,4);
mat B = randu(4,4);
cout << "A:\n" << A << "\n";
//Matrices multiplication
cout << A*B << endl;
return 0;
}

I get the following errors:

'Building target: test'
'Invoking: Cross G++ Linker'

arm-linux-gnueabihf-g++ -L"[path to the liblapack.a,liblas.a and libf2c.a files]" -o "test" ./src/test.o  -llapack -lf2c -lblas

./src/test.o: In function `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*)':
[path to the armadillo library]\include/armadillo_bits/translate_blas.hpp:36: undefined reference to `dgemv_'

./src/teste.o: In function `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*)':
[path to the armadillo library]\include/armadillo_bits/translate_blas.hpp:62: undefined reference to `dgemm_'

collect2.exe: error: ld returned 1 exit status
makefile:45: recipe for target 'test' failed`
make: *** [test] Error 1
"make all" terminated with exit code 2. Build might be incomplete

Very similar problem as in here : Armadillo + BLAS + LAPACK , but on my case the compilation just crashes everytime.

I already cross-compiled another time the libraries to see if was this the problem and had no success.

stateMachine
  • 5,227
  • 4
  • 13
  • 29
gcobot
  • 11
  • 3
  • Most probably a problem with the symbol mangling. The linker error shows a plain c (not mangled) symbol is missing. Take care when including plain c headers in c++ compilation units to enclose them within [`extern "C" { ... } `](https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c) properly. – πάντα ῥεῖ Sep 05 '20 at 20:01
  • First of all thanks for the answer, I'm newbie so I have to ask: the plain c term that you are referencing in the Linker error is the `dgemm_' term? – gcobot Sep 05 '20 at 20:16
  • Yup. This most likely appears because some units were compiled with the c++ compiler and others with the c compiler (or vice versa). The details are explained well in the linked duplicate (it has many sections, but I am confident you'll find it there). – πάντα ῥεῖ Sep 05 '20 at 20:23
  • Well this maybe can be the problem, but I really want to believe that a user of the armadillo library don't need to change the code in the "include/armadillo_bits/***.hpp" files. Anyway I will read all the answers from the linked duplicate I really want to learn how to make this work. – gcobot Sep 05 '20 at 20:40
  • I can reopen the question now you have the link as a base for more research about the probable problem. Anyhow reopening gives others which have met the same problem and fixed it a chance to write an answer here. – πάντα ῥεῖ Sep 05 '20 at 20:46

0 Answers0