从C++打印困难。文件中的文件当文件使用GSL函数时

发布于 2025-01-21 15:29:33 字数 1174 浏览 5 评论 0原文

我正在尝试使用GSL函数在C ++中运行示例脚本。我正在使用Visual Studio代码来编译和执行程序。示例代码如下(我以文件名gsl_bessel_example.cpp将其保存下来),然后我直接从GSL 2.7 Scientific Library Documentation 在这里

#include <stdio.h>
#include <gsl\gsl_sf_bessel.h>

int
main (void)
{
  double x = 5.0;
  double y = gsl_sf_bessel_J0 (x);
  //double y = 10.0;
  printf ("J0(%g) = %.18e\n", x, y);
  return 0;
}

我希望该程序在我编译并执行程序后将以下内容输出到终端:

j0(5)= -1.77596713143143382642E -01 -01

在编译程序时,我在命令中使用以下内容。线:

g++ -Wall gsl_bessel_example.cpp -IC:\msys64\mingw\include -LC:\msys64\mingw\lib -lgsl -lgslcblas

并执行它:

.\a.exe

编译文件时没有错误或警告 - 它可以编译罚款。但是,执行它时我不会获得任何输出。如果我评论行:

double y = gsl_sf_bessel_J0 (x); 

并使用:

double y = 10;

而是重新编译和执行,我会收到我期望的输出(有关结果,请参见附件的图像)。有人知道为什么当我使用GSL函数时,文件不会按预期执行?我已经尝试了GSL文档中提供的其他示例,但对所有示例提供了相似的结果(无输出)。

使用GSL函数的代码和输出的图像

I am trying to run an example script in C++ using GSL functions. I am using Visual Studio Code to compile and execute the program. The example code is below (I saved it under the file name gsl_bessel_example.cpp) and I got it directly from the GSL 2.7 Scientific Library documentation here.

#include <stdio.h>
#include <gsl\gsl_sf_bessel.h>

int
main (void)
{
  double x = 5.0;
  double y = gsl_sf_bessel_J0 (x);
  //double y = 10.0;
  printf ("J0(%g) = %.18e\n", x, y);
  return 0;
}

I expect the program to output the following to the terminal after I have compiled and executed the program:

J0(5) = -1.775967713143382642e-01

When I compile the program, I use the following in the command line:

g++ -Wall gsl_bessel_example.cpp -IC:\msys64\mingw\include -LC:\msys64\mingw\lib -lgsl -lgslcblas

and execute it with:

.\a.exe

There are no errors or warnings given when I compile the file -- it compiles fine. However, I do not get any output when I execute it. If I comment out the line:

double y = gsl_sf_bessel_J0 (x); 

and use:

double y = 10;

instead then recompile and execute, I receive an output I expect (see attached images for the results). Does anyone know why the file will not execute as expected when I use the GSL function? I have tried this for other examples provided in the GSL documentation but have similar results for all (no output).

Image of Code and Output Using GSL Function

Image of Code and Output Not Using GSL Function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2025-01-28 15:29:33

这个答案可能有点晚了,但是我遇到了同样的问题,并认为我会分享我的解决方案。

问题:编译的二进制文件无法找到链接libgsl.dlllibgslcblas.dll libraries

解决方案:

  • 添加&lt; gsl-path&gt;代码> 路径环境变量的路径
  • 重新启动所有终端

是我采取的步骤以找到问题是:

  • 我用32位GCC/GSL编译了源(从在此处)和64-bit gcc/gsl(使用vcpkg安装)。
  • 我在WSL中运行了可执行文件,这给了我“找不到libgsl.dll”的错误。
  • 我放置了libgsl.dlllibgslblas.dll 文件,在&lt; gsl-path&gt; \ gsl \ gsl \ bin \ bin中,在同一目录中。
  • ​工作。

我希望它有帮助。

This answer might be a bit late but I encountered the same problem and thought I'd share my solution.

Problem: the compiled binary cannot find the linked libgsl.dll and libgslcblas.dll libraries

Solution:

  • Add the <gsl-path>\gsl\bin path to the PATH environment variable
  • Restart all terminals

Here are the steps I took to find what the issue was:

  • I compiled the source both with 32-bit gcc/GSL (installed from here) and 64-bit gcc/GSL (installed with vcpkg).
  • I ran the executable in WSL, and it gave me an error of "libgsl.dll not found".
  • I placed the libgsl.dll and libgslblas.dll files found in <gsl-path>\ gsl\bin in the same directory of the .exe and it worked
  • I checked if I had not added the gsl\bin folder to PATH environment variable
  • It was already added, so I had to restart all terminals to make it work.

I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文