从max终端编译c gsl库时出现问题
我有一个c脚本从max终端编译c gsl库时出现问题,c,macos,gcc,terminal,gsl,C,Macos,Gcc,Terminal,Gsl,我有一个c脚本 #include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> int main(void) { const gsl_rng_type * T; gsl_rng * r; int i;
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
int main(void)
{
const gsl_rng_type * T;
gsl_rng * r;
int i;
double a,b;
double num;
a=10;
b=7.2;
gsl_rng_env_setup();
T=gsl_rng_default;
r=gsl_rng_alloc (T);
for(i=0; i<10; i++)
{
num = gsl_ran_gamma(r,a,b);
printf("%.8f \n",num);
}
gsl_rng_free(r);
return 0;
}
这导致了以下输出
gamma.c:5:10: fatal error: 'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>
^
1 error generated.
gamma.c:5:10:致命错误:“未找到gsl/gsl_rng.h”文件
#包括
^
生成1个错误。
这正是我在Linux上编译它的方式,所以我不确定有什么错误,因为我以前在mac上的终端上使用这种格式编译过c脚本。我的猜测是它没有正确链接,但我不确定我需要做什么来修复它。谢谢使用
brew list gsl
或查找gsl/gsl_rng.h
找到您的头文件目录,然后告诉您的编译器头文件在哪里。例如,我需要以下内容:
gcc -Wall -I/usr/local/Cellar/gsl/1.16/include/ gamma.c -o gamma.out -lm -lgsl -lgslcblas
所以我得到了以下错误d:library not found for-lgsl clang:error:linker命令失败,退出代码为1(使用-v查看调用)告诉编译器库在哪里
brew list gsl
然后将库目录附加到链接行-L/usr/local/ceral/gsl/1.16/lib/
gcc -Wall -I/usr/local/Cellar/gsl/1.16/include/ gamma.c -o gamma.out -lm -lgsl -lgslcblas