从C++打印困难。文件中的文件当文件使用GSL函数时
我正在尝试使用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文档中提供的其他示例,但对所有示例提供了相似的结果(无输出)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案可能有点晚了,但是我遇到了同样的问题,并认为我会分享我的解决方案。
问题:编译的二进制文件无法找到链接
libgsl.dll
和libgslcblas.dll
libraries解决方案:
&lt; gsl-path&gt;代码>
路径
环境变量的路径是我采取的步骤以找到问题是:
libgsl.dll
和libgslblas.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
andlibgslcblas.dll
librariesSolution:
<gsl-path>\gsl\bin
path to thePATH
environment variableHere are the steps I took to find what the issue was:
libgsl.dll
andlibgslblas.dll
files found in<gsl-path>\ gsl\bin
in the same directory of the .exe and it workedgsl\bin
folder toPATH
environment variableI hope it helps.