一、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
使用GNU Scientific Library(GSL)及GSL的配置
百度日誌 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/