0

I found a way to print armadillo matrix in gdb on this site . However, what happens if

#include <iostream>
#include <armadillo>


template<class Matrix>
void print_matrix(Matrix matrix) {
matrix.print(std::cout);
}

//provide explicit instantiations of the template function for 
//every matrix type you use somewhere in your program.
template void print_matrix<arma::mat>(arma::mat matrix);
template void print_matrix<arma::cx_mat>(arma::cx_mat matrix); 

is inside debug_armadillo.h file. How call function should be performed? I tried to type:

call 'debug_armadillo.h'::print_matrix<arma::Mat<float>>(C)

but the error I get is:

No symbol "print_matrix" in specified context. 
Community
  • 1
  • 1
user3616359
  • 359
  • 3
  • 20

1 Answers1

1

How call function should be performed?

This call should work. Use Tab completion to autocomplete exact C++ type as suggested in https://stackoverflow.com/a/22766955/72178.

(gdb) call print_matrix<arma::Mat<float> >(C) 

No symbol "print_matrix" in specified context

Make sure that print_matrix function was actually generated in resulting binary. Try to grep demangled symbols, probably exact type differs a bit in template arguments from what you are trying to call:

nm -C your_binary | grep print_matrix
Community
  • 1
  • 1
ks1322
  • 33,961
  • 14
  • 109
  • 164
  • Thanks. However result of your last command is nothing. This probably means that print_matrix is not generated in binary and that's why I get error "No symbol "print_matrix" in specified context.". How can I fix this? The make files seemed fine. – user3616359 Jan 03 '17 at 14:03
  • Make sure that you are including `debug_armadillo.h` from somewhere. Or move `print_matrix` code to some cpp file. – ks1322 Jan 03 '17 at 14:10
  • That is why this is strange. `debug_armadillo.h` is included in makefile and everything seems to be nicely built. And I assume tab completion wouldn't work if that was not the case. – user3616359 Jan 03 '17 at 14:30
  • `debug_armadillo.h` should be also included from some cpp file with `#include` directive. – ks1322 Jan 03 '17 at 14:47
  • You are right I forgot this :( The `print_matrix` is in binary, but now the error is `No symbol "print_matrix" in current context` – user3616359 Jan 03 '17 at 15:40
  • What about `call print_matrix >(C)` ? Note space between `>`. – ks1322 Jan 03 '17 at 16:12