现在的位置: 首页 > 综合 > 正文

GSL的编译和使用

2014年08月29日 ⁄ 综合 ⁄ 共 2452字 ⁄ 字号 评论关闭

    gsl全称GNU Scientific Library ,是用于数值计算的C和C++程序库。据说目前号称有三大库支持科学计算,它们是GNU的gsl,blitz++以及MTL,另外两个还没接触过。粘贴部分介绍如下:
    The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License.
    The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting. There are over 1000 functions in total with an extensive test suite.The complete range of subject areas covered by the library includes, 

Complex Numbers(复数)          Roots of Polynomials(多项式根)
Special Functions(特殊函数)    Vectors and Matrices(向量和矩阵)
Permutations(排列)             Sorting(组合)
BLAS Support                     Linear Algebra(线性代数)
Eigensystems(特征值)           Fast Fourier Transforms(快速傅里叶变换)
Quadrature(求积)               Random Numbers(随机数)

    gsl的源代码可以从GNU的网站下载:http://www.gnu.org/software/gsl/,或从其ftp站点下载:ftp://ftp.gnu.org/gnu/gsl
    我下载的版本是gsl-1.15,编译安装过程参考其INSTALL文件即可:
    To compile GSL you will need an ANSI C-compiler.  After unpacking the distribution the Makefiles can be prepared using the configure command,
    ./configure
    You can then build the library by typing,
    make
    Both static and shared versions of the libraries will be compiled by default.  Compilation of shared libraries can be turned off by specifying the `--disable-shared' option to `configure', e.g.
    ./configure --disable-shared
    The library can be installed using the command,
    make install
    The default installation directory prefix is /usr/local.
    我分别在cygwin和MinGW中进入gsl-1.15目录,依次执行  ./configure、make、make install命令,编译、安装成功后即可在默认安装路径下/usr/local找到生成的库文件libgsl.a和libgslcblas.a,具体分别位于C:\cygwin\lib和C:\MinGW\msys\1.0\local\lib。(安装命令make install可以不执行,搜索出最后想要的两个库文件就行了。)
    接下来便是在自己的工程使用gsl。我使用的IDE是Qt Creater,先将gsl头文件和两个库文件拷贝到了Dependencies/gsl文件夹中,然后在工程文件(.pro)中添加如下语句就可以了:

#gsl

INCLUDEPATH += \
    ../Dependencies \
    ../Dependencies/gsl
LIBS += \
    ../Dependencies/gsl/libgsl.a \
    ../Dependencies/gsl/libgslcblas.a \
     遇到的一个问题是,使用在cygwin中编译的库问题出现了错误,而使用在MinGW中编译的库则不会出现该问题。有关的解释是:

The error you're seeing is due to the fact that MinGW doesn't link the Cygwin DLL by default.

MinGW- and Cygwin-compiled libraries don't play that well with each other - while it's possible to get it to work,it's not really a good idea. Choose one toolchain for your project, which, in this case, means either setting up Code::Blocks so it uses the Cygwin toolchain instead of the bundled MinGW distribution or compiling GSL with MinGW as well.

     此外,若想用Visual Studio 2010编译gsl,可参见http://gladman.plushost.co.uk/oldsite/computing/ 中关于The GNU Scientific Library (v1.15) for Visual Studio 2010的内容

http://blog.csdn.net/myself00/article/details/9022715

抱歉!评论已关闭.