没有权限?执行 example.o 时(gsl 统计样本)

发布于 2024-11-30 07:07:37 字数 1061 浏览 5 评论 0原文

我在我的 Mac 上下载、编译并安装了 GNU Scientific Library (gsl),默认位置为 /usr/local/include/gsl。

为了测试它,我尝试编译并执行示例 C 程序(从 gsl 文档中找到)。

 #include <stdio.h>
 #include <gsl/gsl_statistics.h>

 int
 main(void)
 {
   double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6};
   double mean, variance, largest, smallest;

   mean     = gsl_stats_mean(data, 1, 5);
   variance = gsl_stats_variance(data, 1, 5);
   largest  = gsl_stats_max(data, 1, 5);
   smallest = gsl_stats_min(data, 1, 5);

   printf ("The dataset is %g, %g, %g, %g, %g\n",
          data[0], data[1], data[2], data[3], data[4]);

   printf ("The sample mean is %g\n", mean);
   printf ("The estimated variance is %g\n", variance);
   printf ("The largest value is %g\n", largest);
   printf ("The smallest value is %g\n", smallest);
   return 0;
 }

要编译它,

$ gcc -I /usr/local/include -c example.c

$ ls

example.c example.o

并且要执行它,

$ ./example.o

-bash: ./example.o: Permission returned

发生什么事了?除了我之外还有谁可以运行它?

I downloaded, compiled, and installed the GNU Scientific Library (gsl) on my mac, which locates /usr/local/include/gsl as default.

To test it, I have tried to compile and execute the example C program (found from gsl document).

 #include <stdio.h>
 #include <gsl/gsl_statistics.h>

 int
 main(void)
 {
   double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6};
   double mean, variance, largest, smallest;

   mean     = gsl_stats_mean(data, 1, 5);
   variance = gsl_stats_variance(data, 1, 5);
   largest  = gsl_stats_max(data, 1, 5);
   smallest = gsl_stats_min(data, 1, 5);

   printf ("The dataset is %g, %g, %g, %g, %g\n",
          data[0], data[1], data[2], data[3], data[4]);

   printf ("The sample mean is %g\n", mean);
   printf ("The estimated variance is %g\n", variance);
   printf ("The largest value is %g\n", largest);
   printf ("The smallest value is %g\n", smallest);
   return 0;
 }

To compile it,

$ gcc -I /usr/local/include -c example.c

$ ls

example.c example.o

And, to execute it,

$ ./example.o

-bash: ./example.o: Permission denied

What's happening? Who can run it other than me?

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

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

发布评论

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

评论(1

云雾 2024-12-07 07:07:37

example.o 是一个目标文件,而不是可执行文件。

根据文档(info gsl-ref 阅读它),这应该可行(或者至少接近)。

$ gcc -Wall -I/usr/local/include -c example.c
$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm -o example
$ ./example

example.o is an object file, not an executable.

According to the documentation (info gsl-ref to read it), this should work (or at least it's close).

$ gcc -Wall -I/usr/local/include -c example.c
$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm -o example
$ ./example
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文