目录

GSL

misaraty 更新 | 2024-09-15
前言
GSL基于C的数学库,包含1000+功能,涉及随机数生成、特殊函数和最小二乘法等。

下载

GSL - Github

安装与测试

测试文件test.c
1
2
3
4
5
6
7
8
9
#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;
}

Linux环境

  • 安装
1
./configure --prefix=/backup/home/misaraty/soft/gsl&&make -j 16&&make install

          在.bashrc中添加,

1
2
3
4
#gsl
export C_INCLUDE_PATH=/home/misaraty/soft/gsl/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/home/misaraty/soft/gsl/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/home/misaraty/soft/gsl/lib:$LIBRARY_PATH
  • 测试
1
gcc test.c -lgsl -lgslcblas -O2 -Wall -o test.out && ./test.out
  • 自动安装&测试
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
tar -zxvf gsl-2.4.tar.gz && cd ./gsl-2.4 &&./configure --prefix=$(pwd)&&make -j&&make install &&cd ../&& cp -r ./gsl-2.4/include ./gsl-2.4/lib $(pwd) && rm -rf ./gsl-2.4 #&& rm -rf ./gsl-2.4.tar.gz
echo "The gsl's location is" $(pwd)'.'
cat >> $HOME/.bashrc <<EOF
#gsl
export C_INCLUDE_PATH=$(pwd)/include:\$C_INCLUDE_PATH
export LD_LIBRARY_PATH=$(pwd)/lib:\$LD_LIBRARY_PATH
export LIBRARY_PATH=$(pwd)/lib:\$LIBRARY_PATH
EOF
source ~/.bashrc
echo "The gsl's environment variable has been added to ~/.bashrc."
echo "test gsl……"
gcc test.c -lgsl -lgslcblas -O2 -Wall -o test.out && ./test.out && rm -rf test.out

Windows环境

  • 测试
1
gcc test.c -Wall -I"C:\gsl-1.15-dev-win64\include" -L"C:\gsl-1.15-dev-win64\bin" -lgslcblas-0 -lgsl-0 -lm -o test

Notepad++调用

1
cmd /k chcp 65001 >nul && gcc -Wall -I"C:\gsl-1.15-dev-win64\include" -L"C:\gsl-1.15-dev-win64\bin" -lgslcblas-0 -lgsl-0 -lm -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" && CLS && "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" & PAUSE & EXIT