简体   繁体   English

将GNU科学库与Code :: Blocks一起使用时出错

[英]Error using GNU scientific library with Code::Blocks

I am having an extraordinary problem with my current Code::Blocks (GNU GCC compiler) setup. 我当前的Code :: Blocks(GNU GCC编译器)设置存在一个特殊问题。 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. 编译器似乎有选择地运行某些GSL函数,但是由于某些原因,当命令执行其他GSL函数时,似乎有很大的问题。

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 例如,我从以下目标位置提取了以下代码: 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: 我假设由于代码是从GNU官方网站派生的,所以代码是正确的:

#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> 进程返回-1073741819 <0xC0000005>

I have spent a lot of time trying to discover the source of the bug but have sadly not had much success. 我花了很多时间试图找出bug的来源,但可惜并没有取得太大的成功。 I am generally not sure why there is a crash at all. 我通常不确定为什么会发生崩溃。 The debugger prints no warnings or error messages. 调试器不打印警告或错误消息。

I'm going to suggest that perhaps you have mismatched headers and libraries. 我建议您可能有不匹配的标头和库。 Perhaps there is more than one version of GSL installed. 也许安装了多个版本的GSL。 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. 我去查找gsl_vector_view的typedef并结束到这里,您甚至可以看出版本甚至不支持该struct类型的v​​ector成员。

You will get this 0xC0000005 error, typically when you use some unitialised pointer. 您通常会在使用某些统一指针时收到此0xC0000005错误。 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. 并不是说您的指针在这里未初始化。.我想说的是&column.vector的“ vector”位被解释&column.vector预期的东西。

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/ 这里有一些有关如何配置它们的详细信息: http : //www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM