没有权限?执行example.of时(gsl statistics sample)

时间:2011-08-18 00:51:10

标签: macos gcc gsl

我在我的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 denied

发生了什么事?除了我以外谁能管它?

1 个答案:

答案 0 :(得分:1)

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