0

I use armadillo library. somewhere I get this exception:

error: Mat::init(): size is fixed and hence cannot be changed

terminate called after throwing an instance of 'std::logic_error'
  what():  Mat::init(): size is fixed and hence cannot be changed
Aborted (core dumped)

I know why. But I dont know where.

Is there any way to obtained the line causing this problem? is valgrind or any other tool able to do that?

Update:

compile code:

g++ -g  -Wall -Wfatal-errors -Wextra -std=c++11 
            main.cpp -lboost_filesystem -lboost_system
ar2015
  • 5,558
  • 8
  • 53
  • 110
  • Have you tried looking at the backtrace in the core files? The last line of your output says `core dumped`. – RomanK Mar 13 '15 at 06:45
  • @RomanK, how to do that? btw, I use g++ to compile. I dont use IDE. – ar2015 Mar 13 '15 at 06:45
  • To know where , debug it... add some breakpoint... – Ron Tang Mar 13 '15 at 06:46
  • 1
    @ar2015 - Run `gdb` with the path to your binary and path to your core file as parameters. If you have a single thread, hit `bt`. Make sure you've compiled with debug symbols. There's any number of `gdb `primers out there. – RomanK Mar 13 '15 at 06:48
  • what do you mean by core file? i typed `gdb a.out` and it went to gdb command line and i dont know what to do? – ar2015 Mar 13 '15 at 06:55
  • "And path your core file". Two parameters, not just `a.out`. Here, I googled the relevant thread for you: http://stackoverflow.com/questions/8305866/how-to-analyze-a-programs-core-dump-file – RomanK Mar 13 '15 at 06:59
  • @RomanK thanks. i did that. however, how to see the full backtrace? – ar2015 Mar 13 '15 at 07:03
  • Run the `bt` command. – RomanK Mar 13 '15 at 07:04

1 Answers1

0

Can you post a small snippet of the code where the error comes in? I had similar error but dont remember what caused it but try storing the result of the command in some other variable and check it. And put "cout" to find the statement causing the error.

letsBeePolite
  • 2,183
  • 1
  • 22
  • 37
  • As far as I remember, it was something like this `fixed_vector=normal_vector_different_size`. But I dont have the code since I have fixed it. – ar2015 Mar 15 '15 at 22:14