GSL插值函数编译链接出错解决方法

在Windows平台使用VS2017社区版将开源数学库GSL编译链接成DLL后,使用官方示例测试其插值函数。在编译链接该示例过程中报

LNK2001: unresolved external symbol _gsl_interp_cspline

的错误。

解决方法如下,在示例开始处定义如下宏即可。

#define GSL_DLL

完整可运行示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define GSL_DLL

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>

int
main (void)
{
int i;
double xi, yi, x[10], y[10];

printf ("#m=0,S=17\n");

for (i = 0; i < 10; i++)
{
x[i] = i + 0.5 * sin (i);
y[i] = i + cos (i * i);
printf ("%g %g\n", x[i], y[i]);
}

printf ("#m=1,S=0\n");

{
gsl_interp_accel *acc
= gsl_interp_accel_alloc ();
gsl_spline *spline
= gsl_spline_alloc (gsl_interp_cspline, 10);

gsl_spline_init (spline, x, y, 10);

for (xi = x[0]; xi < x[9]; xi += 0.01)
{
yi = gsl_spline_eval (spline, xi, acc);
printf ("%g %g\n", xi, yi);
}
gsl_spline_free (spline);
gsl_interp_accel_free (acc);
}
return 0;
}

参考链接

  1. Interpolation,by gsl homepage.
  2. [Help-gsl] LNK2001: unresolved external symbol _gsl_interp_cspline,by lists.gnu.org.
  3. [Help-gsl] Re: LNK2001: unresolved external symbol _gsl_interp_cspline,by lists.gnu.org.
  4. C++求积分代码,by Firekisser.
  5. matlab代码—插值,by 从小练武功.