2.GSLを使った例としてベッセル関数の値を求めてみます。以下にプログラム例を示します。
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main(void){
double x = 5.0;
double y = gsl_sf_bessel_J0(x);
printf("J0(%g) = %.18e\n",x,y);
return 0;
}
これをexample.cとして保存します。次に以下のコマンドを入力して実行します。
gcc -I/usr/local/include -I/usr/include -L/usr/local/lib -L/usr/lib -o example example.c -lgsl -lgslcblas -lm
exampleの実行ファイルが出力されます。次に以下のコマンドを入力して実行します。
./example
この時
./example: error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory
このようなエラーが出たら
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
入力してから再び実行して下さい。
J0(5)=-1.775967713143382642e-01
結果が表示されます。