编译好的版本放到了这里,包括静态库和动态库。大家直接用吧。
http://download.csdn.net/detail/liyuanbhu/9618257
Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(4)
gsl_permutation 模块
#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------
QT -= core gui
TARGET = gsl_permutation
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ./include/
SOURCES += \
source/permutation/canonical.c \
source/permutation/file.c \
source/permutation/init.c \
source/permutation/inline.c \
source/permutation/permutation.c \
source/permutation/permute.c
unix {
target.path = /usr/lib
INSTALLS += target
}
DISTFILES +=
测试代码:
#include <stdio.h>
#include <gsl/gsl_permutation.h>
void permutation_test (void)
{
gsl_permutation * p = gsl_permutation_alloc (3);
gsl_permutation_init (p);
do
{
gsl_permutation_fprintf (stdout, p, " %u");
printf ("\n");
}
while (gsl_permutation_next(p) == GSL_SUCCESS);
gsl_permutation_free (p);
}
输出结果:
0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0
gsl_combination 模块
gsl_combination.h 拷贝到 include/gsl
项目文件:
#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------
QT -= core gui
TARGET = gsl_combination
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ./include/
SOURCES += \
source/combination/combination.c \
source/combination/file.c \
source/combination/init.c \
source/combination/inline.c
unix {
target.path = /usr/lib
INSTALLS += target
}
DISTFILES +=
测试代码:
#include <stdio.h>
#include <gsl/gsl_combination.h>
void combination_test(void)
{
gsl_combination * c;
size_t i;
printf ("All subsets of {0,1,2,3} by size:\n");
for (i = 0; i <= 4; i++)
{
c = gsl_combination_calloc (4, i);
do
{
printf ("{");
gsl_combination_fprintf (stdout, c, " %u");
printf (" }\n");
}
while (gsl_combination_next (c) == GSL_SUCCESS);
gsl_combination_free(c);
}
}
gsl_multiset 模块
#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------
QT -= core gui
TARGET = gsl_multiset
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ./include/
SOURCES += \
source/multiset/file.c \
source/multiset/init.c \
source/multiset/inline.c \
source/multiset/multiset.c
unix {
target.path = /usr/lib
INSTALLS += target
}
DISTFILES +=
测试代码:
#include <stdio.h>
#include <gsl/gsl_multiset.h>
void multiset_test (void)
{
gsl_multiset * c;
size_t i;
printf ("All multisets of {0,1,2,3} by size:\n") ;
for (i = 0; i <= 4; i++)
{
c = gsl_multiset_calloc (4, i);
do
{
printf ("{");
gsl_multiset_fprintf (stdout, c, " %u");
printf (" }\n");
}
while (gsl_multiset_next (c) == GSL_SUCCESS);
gsl_multiset_free (c);
}
}
输出结果:
All multisets of {0,1,2,3} by size:
{ }
{ 0 }
{ 1 }
{ 2 }
{ 3 }
{ 0 0 }
{ 0 1 }
{ 0 2 }
{ 0 3 }
{ 1 1 }
{ 1 2 }
{ 1 3 }
{ 2 2 }
{ 2 3 }
{ 3 3 }
{ 0 0 0 }
{ 0 0 1 }
{ 0 0 2 }
{ 0 0 3 }
{ 0 1 1 }
{ 0 1 2 }
{ 0 1 3 }
{ 0 2 2 }
{ 0 2 3 }
{ 0 3 3 }
{ 1 1 1 }
{ 1 1 2 }
{ 1 1 3 }
{ 1 2 2 }
{ 1 2 3 }
{ 1 3 3 }
{ 2 2 2 }
{ 2 2 3 }
{ 2 3 3 }
{ 3 3 3 }
{ 0 0 0 0 }
{ 0 0 0 1 }
{ 0 0 0 2 }
{ 0 0 0 3 }
{ 0 0 1 1 }
{ 0 0 1 2 }
{ 0 0 1 3 }
{ 0 0 2 2 }
{ 0 0 2 3 }
{ 0 0 3 3 }
{ 0 1 1 1 }
{ 0 1 1 2 }
{ 0 1 1 3 }
{ 0 1 2 2 }
{ 0 1 2 3 }
{ 0 1 3 3 }
{ 0 2 2 2 }
{ 0 2 2 3 }
{ 0 2 3 3 }
{ 0 3 3 3 }
{ 1 1 1 1 }
{ 1 1 1 2 }
{ 1 1 1 3 }
{ 1 1 2 2 }
{ 1 1 2 3 }
{ 1 1 3 3 }
{ 1 2 2 2 }
{ 1 2 2 3 }
{ 1 2 3 3 }
{ 1 3 3 3 }
{ 2 2 2 2 }
{ 2 2 2 3 }
{ 2 2 3 3 }
{ 2 3 3 3 }
{ 3 3 3 3 }
gsl_sort 模块
多个代码中的 inline 需要替换为 __inline。
项目文件:
#-------------------------------------------------
#
# Project created by QtCreator 2016-08-26T20:38:46
#
#-------------------------------------------------
QT -= core gui
TARGET = gsl_sort
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ./include/
SOURCES += \
source/sort/sort.c \
source/sort/sortind.c \
source/sort/sortvec.c \
source/sort/sortvecind.c \
source/sort/subset.c \
source/sort/subsetind.c
unix {
target.path = /usr/lib
INSTALLS += target
}
DISTFILES +=
测试代码:
#include <gsl/gsl_rng.h>
#include <gsl/gsl_sort_double.h>
int sort_test (void)
{
const gsl_rng_type * T;
gsl_rng * r;
size_t i, k = 5, N = 100000;
double * x = malloc (N * sizeof(double));
double * small = malloc (k * sizeof(double));
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
for (i = 0; i < N; i++)
{
x[i] = gsl_rng_uniform(r);
}
gsl_sort_smallest (small, k, x, 1, N);
printf ("%d smallest values from %d\n", k, N);
for (i = 0; i < k; i++)
{
printf ("%d: %.18f\n", i, small[i]);
}
free (small);
gsl_rng_free (r);
return 0;
}
这个测试代码用到了 gsl_rng 模块的功能。我们还没有动手制作 gsl_rng 模块,所以这个代码暂时还不能编译。等到 完成 gsl_rng 模块后,再进行这个代码的测试。