1

I am having an extraordinary problem with my current Code::Blocks (GNU GCC compiler) setup. The compiler seems to selectively run some GSL functions, but seems for some reason to have great problems when commanded to execute other GSL functions.

For example, I have lifted the following code from the following destination: https://www.gnu.org/software/gsl/manual/html_node/Example-programs-for-matrices.html

I assume that because the code is derived from the official GNU website, that the code is correct:

#include <math.h>
#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>

int
main (void)
{
  size_t i,j;

  gsl_matrix *m = gsl_matrix_alloc (10, 10);

  for (i = 0; i < 10; i++)
    for (j = 0; j < 10; j++)
      gsl_matrix_set (m, i, j, sin (i) + cos (j));

  for (j = 0; j < 10; j++)
    {
      gsl_vector_view column = gsl_matrix_column (m, j);
      double d;

      d = gsl_blas_dnrm2 (&column.vector);

      printf ("matrix column %d, norm = %g\n", j, d);
    }

  gsl_matrix_free (m);

  return 0;
}

From debugging, I have learned that the source of the error is the following line:

d = gsl_blas_dnrm2 (&column.vector);

The compiler crashes at this point and prints the following error message:

Process returned -1073741819 <0xC0000005>

I have spent a lot of time trying to discover the source of the bug but have sadly not had much success. I am generally not sure why there is a crash at all. The debugger prints no warnings or error messages.

TBradley
  • 31
  • 1
  • 6
  • What debugging have you done? Is it crashing when it runs or failing to compile? On my linux system it compiles successfully with `gcc gsl.c -lm -lgsl -lgslcblas` and runs fine – Tom Fenech Jul 09 '14 at 17:20
  • are you sure you meant the 'compiler' crashes? – robert Jul 09 '14 at 17:22
  • My mistake, I meant the program itself crashes upon execution. I am using an application (codeblocks) which compiles and then immediately runs the program. The code compiles successfully. When I say debugging I mean I have used print statement to identify the exact point at which the flow of execution is terminated. This is at the line 'd = gsl_blas_dnrm2 (&column.vector);' – TBradley Jul 09 '14 at 18:21
  • I did a quick google for your error, it's pretty common http://cboard.cprogramming.com/cplusplus-programming/99222-0xc0000005-error.html there are some tips for diagnosis at this page. – robert Jul 10 '14 at 15:17
  • what operating system are you using? Seems to be a known issue under windows ... http://forums.codeblocks.org/index.php/topic,8675.msg63238.html – robert Jul 10 '14 at 15:43

1 Answers1

0

I'm going to suggest that perhaps you have mismatched headers and libraries. Perhaps there is more than one version of GSL installed. You have the headers from one version referenced in your source, and the linker is referencing the libs from other version.

I went looking up the typedef of the gsl_vector_view and ended up here, and you may be even able to discern that this version doesn't even support the vector member of that struct type.

You will get this 0xC0000005 error, typically when you use some unitialised pointer. Its not that your pointer is uninitialised here though .. I'd say what's happening is the 'vector' bit of &column.vector is being interpreted as something other than what is intended.

In summary, I think this is some kind of environmental issue, perhaps with your linker settings? There are some details on how to configure these here: http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/

Hope this helps.

robert
  • 4,612
  • 2
  • 29
  • 39
  • 1
    Thank you for your response. I was using Windows but I am now using Linux and the program works fine. Once I have some time, I will make sure to look carefully at what you have written to see if I can fix the problem when trying to code in C when using Windows. – TBradley Jul 12 '14 at 13:08