一、GSL介绍
GNU科学计算函数库GSL(GNU Scientific Library)是一个强大的C/C++数值计算函数库,它是一个自由软件,是GNU项目软件的一个部分,遵循GPL协议。GSL是一个为C和C++程序员提供的科学数值运算库。该科学计算库异常强大,函数库提供了大量的数值计算程序
,如随机函数、特殊函数和拟合函数等等,整个函数库大约有1000多个函数,几乎涵盖了科学计算的各个方面。提供了如下方面的支持:
Complex Numbers Roots of Polynomials Special Functions
Vectors and Matrices Permutations Sorting
BLAS Support Linear Algebra Eigensystems
Fast Fourier Transforms Quadrature Random Numbers
Quasi-Random Sequences Random Distributions Statistics
Histograms N-Tuples Monte Carlo Integration
Simulated Annealing Differential Equations Interpolation
Numerical Differentiation Chebyshev Approximation Series Acceleration
Discrete Hankel Transforms Root-Finding Minimization
Least-Squares Fitting Physical Constants IEEE Floating-Point
Discrete Wavelet Transforms Basis splines
该函数库的主页是:http://www.gnu.org/software/gsl/gsl.html。不过遗憾的是原始GSL并不支持不支持windows平台,可所幸的是有人做了GSL在windows上的移植工作,详见http://gnuwin32.sourceforge.net/packages/gsl.htm,目前版本是1.8。
二、下载gsl
1、从http://gnuwin32.sourceforge.net/packages/gsl.htm下载Complete package, except sources和Sources两个exe文件。
三、安装
1、 首先安装从http://gnuwin32.sourceforge.net/packages/gsl.htm下载的两个文件gsl-1.8.exe和gsl-1.8-src.exe。
四、设置Visual C++ 6.0编译环境
1、生成lib文件。发现安装目录lib下并没有libgsl.lib,libgslcblas.lib这两个文件,倒是有两个扩展名为def和a(linux下库文件包格式)的文件,因此必须进行转换。
l 开始菜单,点击运行,输入cmd。
l 进入gsl库的lib目录下依次输入以下两条语句:
lib /machine:i386 /def:libgsl.def
lib /machine:i386 /def:libgslcblas.def
再看lib目录下,发现有了libgsl.lib,libgslcblas.lib这两个文件。
2、将x:/Program Files/GnuWin32l/bin中的libgsl.dll和libgslcblas.dll复制到x:/VC98/Bin;将/include整个Gsl目录复制到x:/VC98/include下;/lib目录下的所有.lib文件全部复制到x:/VC98/Lib下。
3、 新建一个工程用于测试,。然后在该项目的project-settings-link,在object/library modules中加入你用到的库文件,如libgsl.lib libgslcblas.lib,用空格隔开。
五、测试Gsl函数库
#define GSL_DLL
#include <gsl/gsl_spline.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <gl/glut.h>
#include <gl/gl.h>
void Display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
const size_t n = 4;
double x[] = {0,0.333336,0.666666,1};
double y[] = {0,0.5,0.9,0};
gsl_interp* interps[3] = {NULL,NULL,NULL};
interps[0] = gsl_interp_alloc(gsl_interp_linear,n);
interps[1] = gsl_interp_alloc(gsl_interp_polynomial,n);
interps[2] = gsl_interp_alloc(gsl_interp_cspline,n);
gsl_interp_init(interps[0],x,y,n);
gsl_interp_init(interps[1],x,y,n);
gsl_interp_init(interps[2],x,y,n);
gsl_interp_accel* acc = gsl_interp_accel_alloc();
glBegin(GL_LINE_STRIP);
for(double t=0.0; t<=1.025; t+=0.025)
{
glColor3f(1,0,0);
glVertex3f(t,gsl_interp_eval(interps[0],x,y,t,acc),0.0);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(double t=0.0; t<=1.025; t+=0.025)
{
glColor3f(0,1,0);
glVertex3f(t,gsl_interp_eval(interps[1],x,y,t,acc),0.0);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(double t=0.0; t<=1.025; t+=0.025)
{
glColor3f(0,0,1);
glVertex3f(t,gsl_interp_eval(interps[2],x,y,t,acc),0.0);
}
glEnd();
gsl_interp_accel_free(acc);
gsl_interp_free(interps[0]);
gsl_interp_free(interps[1]);
gsl_interp_free(interps[2]);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(512,512);
glutCreateWindow("GSL Interpolation");
glutDisplayFunc(Display);
glClearColor(1,1,1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1,-1,0);
glScalef(2,2,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,512,512);
glLineWidth(4.0);
glutMainLoop();
return 0;
}运行结果:
说明Gsl函数库已经可以使用了。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mooncircle/archive/2010/04/30/5545448.aspx
百度日志 2009-05-26 12:45:43 阅读181 评论1 字号:大中小
作者:彭军
邮件:hellotim##foxmail.com
近来帮朋友编译一个SIFT匹配的程序,可是里面不仅用到了OpenCV,而且用到了GSL,但是在编译的过程中,OpenCV的配置是没有什么问题了,可是GSL一直不行,在用VC6.0进行编译的时候,总是出现类似与如下的错误:
xform.obj : error LNK2001: unresolved external symbol _gsl_rng_free
xform.obj : error LNK2001: unresolved external symbol _gsl_rng_set
xform.obj : error LNK2001: unresolved external symbol _gsl_rng_alloc
xform.obj : error LNK2001: unresolved external symbol _gsl_rng_mt19937
xform.obj : error LNK2001: unresolved external symbol _gsl_sf_choose
xform.obj : error LNK2001: unresolved external symbol _gsl_rng_uniform_int
一想既然是LINK时的错误,肯定是lib文件有关系了。看到GSL的lib文件夹下面并没有后缀名为lib的文件。但是又看到有后缀名为def的文件,我知道通过def文件是可以导出dll和lib文件的了。而且在网络上也看到可以用VS的lib命令来导出适合VS用的.lib文件,于是打开cmd窗口。
D:/Program Files/GnuWin32/lib>lib /machine:i386 /def:libgsl.def
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Creating library libgsl.lib and object libgsl.exp
D:/Program Files/GnuWin32/lib>lib /machine:i386 /def:libgslcblas.def
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Creating library libgslcblas.lib and object libgslcblas.exp
D:/Program Files/GnuWin32/lib>
可以看到lib文件夹下已经有了libgsl.lib和libgslcblas.lib这样的话,我们只要将这两个lib文件添加到工程Link页中就可以了,如下:
当然了,要用GSL的话,也需要在VC的目录中添加GSL的include目录、lib目录和bin目录,如下:
从添加的Include目录可以看出,当你用GSL里面的头文件时,需要类似与这样的引用:
#include <gsl/gsl_rng.h>当然,如果你在添加Include目录是添加的是:D:/Program Files/GnuWin32/include/gsl
那么就不需要前面的gsl,只要如此引用就可以了:#include <gsl_rng.h>
还有一点需要说明的是GSL中已经没有gsl_rng_free.h了,所以你需将其改为gsl_rng.h
你可以在这里下载这个经典SIFT的图像匹配程序的VC程序:
http://download.csdn.net/source/1352136
你可以在这里下载GSL(GNU Scientific Library)1.8:
http://download.csdn.net/source/1352070
http://blog.163.com/jinux@126/blog/static/12139366820096495233699/