Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(3)

编译好的版本放到了这里,包括静态库和动态库。大家直接用吧。
http://download.csdn.net/detail/liyuanbhu/9618257

Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(3)

上一篇博客中介绍了如何生成 gsl_sys gsl_err gsl_complex 和 gsl_poly 模块。

今天继续介绍如何生成 gsl 的其他部分。

gsl_specfunc 模块

这个模块内提供的是多种特殊函数。

首先将所有 gsl_ 开头的头文件都拷贝到 include/gsl 目录中。
另外, gsl_specfunc 模块还依赖 gsl_block 、gsl_vector 和 gsl_matrix 模块。所以也要把这三个模块的头文件拷贝过来。

另外,这个模块的代码写得不太严谨,里面多出用到了 inline 。可是 Visual C++ 编译器不支持 C99 的 inline 功能。解决办法是把代码中所有的 inline 都替换为 __inline.

项目文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------

QT       -= core gui

TARGET = gsl_specfunc
TEMPLATE = lib
CONFIG += staticlib

INCLUDEPATH += ./include/

SOURCES += \
    source/specfunc/airy.c \
    source/specfunc/airy_der.c \
    source/specfunc/airy_zero.c \
    source/specfunc/atanint.c \
    source/specfunc/bessel.c \
    source/specfunc/bessel_amp_phase.c \
    source/specfunc/bessel_i.c \
    source/specfunc/bessel_I0.c \
    source/specfunc/bessel_I1.c \
    source/specfunc/bessel_In.c \
    source/specfunc/bessel_Inu.c \
    source/specfunc/bessel_j.c \
    source/specfunc/bessel_J0.c \
    source/specfunc/bessel_J1.c \
    source/specfunc/bessel_Jn.c \
    source/specfunc/bessel_Jnu.c \
    source/specfunc/bessel_k.c \
    source/specfunc/bessel_K0.c \
    source/specfunc/bessel_K1.c \
    source/specfunc/bessel_Kn.c \
    source/specfunc/bessel_Knu.c \
    source/specfunc/bessel_olver.c \
    source/specfunc/bessel_sequence.c \
    source/specfunc/bessel_temme.c \
    source/specfunc/bessel_y.c \
    source/specfunc/bessel_Y0.c \
    source/specfunc/bessel_Y1.c \
    source/specfunc/bessel_Yn.c \
    source/specfunc/bessel_Ynu.c \
    source/specfunc/bessel_zero.c \
    source/specfunc/beta.c \
    source/specfunc/beta_inc.c \
    source/specfunc/clausen.c \
    source/specfunc/coulomb.c \
    source/specfunc/coulomb_bound.c \
    source/specfunc/coupling.c \
    source/specfunc/dawson.c \
    source/specfunc/debye.c \
    source/specfunc/dilog.c \
    source/specfunc/elementary.c \
    source/specfunc/ellint.c \
    source/specfunc/elljac.c \
    source/specfunc/erfc.c \
    source/specfunc/exp.c \
    source/specfunc/expint.c \
    source/specfunc/expint3.c \
    source/specfunc/fermi_dirac.c \
    source/specfunc/gamma.c \
    source/specfunc/gamma_inc.c \
    source/specfunc/gegenbauer.c \
    source/specfunc/hyperg.c \
    source/specfunc/hyperg_0F1.c \
    source/specfunc/hyperg_1F1.c \
    source/specfunc/hyperg_2F0.c \
    source/specfunc/hyperg_2F1.c \
    source/specfunc/hyperg_U.c \
    source/specfunc/laguerre.c \
    source/specfunc/lambert.c \
    source/specfunc/legendre_con.c \
    source/specfunc/legendre_H3d.c \
    source/specfunc/legendre_P.c \
    source/specfunc/legendre_poly.c \
    source/specfunc/legendre_Qn.c \
    source/specfunc/log.c \
    source/specfunc/mathieu_angfunc.c \
    source/specfunc/mathieu_charv.c \
    source/specfunc/mathieu_coeff.c \
    source/specfunc/mathieu_radfunc.c \
    source/specfunc/mathieu_workspace.c \
    source/specfunc/poch.c \
    source/specfunc/pow_int.c \
    source/specfunc/psi.c \
    source/specfunc/result.c \
    source/specfunc/shint.c \
    source/specfunc/sinint.c \
    source/specfunc/synchrotron.c \
    source/specfunc/transport.c \
    source/specfunc/trig.c \
    source/specfunc/zeta.c

unix {
    target.path = /usr/lib
    INSTALLS += target
}

DISTFILES +=

HEADERS += \
    source/specfunc/bessel.h \
    source/specfunc/bessel_amp_phase.h \
    source/specfunc/bessel_olver.h \
    source/specfunc/bessel_temme.h \
    source/specfunc/chebyshev.h \
    source/specfunc/check.h \
    source/specfunc/error.h \
    source/specfunc/eval.h \
    source/specfunc/hyperg.h \
    source/specfunc/legendre.h \
    source/specfunc/recurse.h

编译之后就能生成 gsl_specfunc.lib 了。虽然我们还没有生成 gsl_vector 、gsl_matrix 和 gsl_block 模块,但是我们还是可以测试 gsl_specfunc 模块的。 因为用到的这三个模块的功能都 inline 进我们的模块中了。

所以 gsl_specfunc 编译时依赖 gsl_vector 、gsl_matrix 和 gsl_block 模块,运行时不依赖。

测试代码如下:

#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_bessel.h>

void specfunc_test()
{
    double x = 5.0;
    gsl_sf_result result;
    double expected = -0.17759677131433830434739701;
    int status = gsl_sf_bessel_J0_e (x, &result);
    printf ("status = %s\n", gsl_strerror(status));
    printf ("J0(5.0) = %.18f\n +/- % .18f\n", result.val, result.err);
    printf ("exact = %.18f\n", expected);
}

gsl_block 模块

templates_on.h 和 templates_off.h 拷贝到 include 目录中。

项目文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------

QT       -= core gui

TARGET = gsl_block
TEMPLATE = lib
CONFIG += staticlib

INCLUDEPATH += ./include/

SOURCES += \
    source/block/block.c \
    source/block/file.c \
    source/block/init.c

unix {
    target.path = /usr/lib
    INSTALLS += target
}

DISTFILES +=

测试代码如下:

#include <gsl/gsl_block.h>
void block_test()
{
    gsl_block * b = gsl_block_alloc (100);
    printf ("length of block = %u\n", b->size);
    printf ("block data address = %#x\n", b->data);
    gsl_block_free (b);
}

gsl_vector 模块

项目文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------

QT       -= core gui

TARGET = gsl_vector
TEMPLATE = lib
CONFIG += staticlib

INCLUDEPATH += ./include/

SOURCES += \
    source/vector/copy.c \
    source/vector/file.c \
    source/vector/init.c \
    source/vector/minmax.c \
    source/vector/oper.c \
    source/vector/prop.c \
    source/vector/reim.c \
    source/vector/subvector.c \
    source/vector/swap.c \
    source/vector/vector.c \
    source/vector/view.c

unix {
    target.path = /usr/lib
    INSTALLS += target
}

DISTFILES +=

测试代码如下:

void vector_test()
{
    int i;
    gsl_vector * v = gsl_vector_alloc (100);
    for (i = 0; i < 100; i++)
    {
        gsl_vector_set (v, i, 1.23 + i);
    }
    {
        FILE * f = fopen ("test.dat", "w");
        gsl_vector_fprintf (f, v, "%.5g");
        fclose (f);
    }
    gsl_vector_free (v);


    v = gsl_vector_alloc (10);
    {
        FILE * f = fopen ("test.dat", "r");
        gsl_vector_fscanf (f, v);
        fclose (f);
    }
    for (i = 0; i < 10; i++)
    {
        printf ("%g\n", gsl_vector_get(v, i));
    }
    gsl_vector_free (v);

}

gsl_matrix 模块

项目文件:

#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------

QT       -= core gui

TARGET = gsl_matrix
TEMPLATE = lib
CONFIG += staticlib

INCLUDEPATH += ./include/

SOURCES += \
    source/matrix/copy.c \
    source/matrix/file.c \
    source/matrix/getset.c \
    source/matrix/init.c \
    source/matrix/matrix.c \
    source/matrix/minmax.c \
    source/matrix/oper.c \
    source/matrix/prop.c \
    source/matrix/rowcol.c \
    source/matrix/submatrix.c \
    source/matrix/swap.c \
    source/matrix/view.c

unix {
    target.path = /usr/lib
    INSTALLS += target
}

DISTFILES +=

测试代码:

#include <gsl/gsl_matrix.h>

void matrix_test()
{
    int i, j, k = 0;
    gsl_matrix * m = gsl_matrix_alloc (100, 100);
    gsl_matrix * a = gsl_matrix_alloc (100, 100);
    for (i = 0; i < 100; i++)
    for (j = 0; j < 100; j++)
    gsl_matrix_set (m, i, j, 0.23 + i + j);
    {
    FILE * f = fopen ("test.dat", "wb");
    gsl_matrix_fwrite (f, m);
    fclose (f);
    }
    {
    FILE * f = fopen ("test.dat", "rb");
    gsl_matrix_fread (f, a);
    fclose (f);
    }
    for (i = 0; i < 100; i++)
    for (j = 0; j < 100; j++)
    {
    double mij = gsl_matrix_get (m, i, j);
    double aij = gsl_matrix_get (a, i, j);
    if (mij != aij) k++;
    }
    gsl_matrix_free (m);
    gsl_matrix_free (a);
    printf ("differences = %d (should be zero)\n", k);
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值