问题描述
我正在尝试从GSL文档中编译示例.Windows,在conda下安装了Cmake + MSVS + GSL 2.6.
I am trying to compile examples from GSL documentation. Windows, Cmake + MSVS + GSL 2.6 installed under conda.
基本示例已编译并可以正常工作:
Basic example gets compiled and works just fine:
cmake_minimum_required(VERSION 3.15)
project(test)
find_package(GSL REQUIRED)
add_executable(test)
target_sources(test PRIVATE main.cpp)
target_include_directories(test PRIVATE "${GSL_INCLUDE_DIRS}")
target_link_libraries(test "${GSL_LIBRARIES}")
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
但是此失败,并带有链接错误:
But this one fails with a linkage error:
错误LNK2001:无法解析的外部符号gsl_odeiv2_step_rk8pd
#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
int
func (double t, const double y[], double f[],
void *params)
{
(void)(t); /* avoid unused parameter warning */
double mu = *(double *)params;
f[0] = y[1];
f[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1);
return GSL_SUCCESS;
}
int
jac (double t, const double y[], double *dfdy,
double dfdt[], void *params)
{
(void)(t); /* avoid unused parameter warning */
double mu = *(double *)params;
gsl_matrix_view dfdy_mat
= gsl_matrix_view_array (dfdy, 2, 2);
gsl_matrix * m = &dfdy_mat.matrix;
gsl_matrix_set (m, 0, 0, 0.0);
gsl_matrix_set (m, 0, 1, 1.0);
gsl_matrix_set (m, 1, 0, -2.0*mu*y[0]*y[1] - 1.0);
gsl_matrix_set (m, 1, 1, -mu*(y[0]*y[0] - 1.0));
dfdt[0] = 0.0;
dfdt[1] = 0.0;
return GSL_SUCCESS;
}
int
main (void)
{
double mu = 10;
gsl_odeiv2_system sys = {func, jac, 2, &mu};
gsl_odeiv2_driver * d =
gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rk8pd,
1e-6, 1e-6, 0.0);
int i;
double t = 0.0, t1 = 100.0;
double y[2] = { 1.0, 0.0 };
for (i = 1; i <= 100; i++)
{
double ti = i * t1 / 100.0;
int status = gsl_odeiv2_driver_apply (d, &t, ti, y);
if (status != GSL_SUCCESS)
{
printf ("error, return value=%d\n", status);
break;
}
printf ("%.5e %.5e %.5e\n", t, y[0], y[1]);
}
gsl_odeiv2_driver_free (d);
return 0;
}
gsl_odeiv2_step_rk8pd
在GSL中的某处定义如下: GSL_VAR const gsl_odeiv2_step_type * gsl_odeiv2_step_rk8pd;
,其中 GSL_VAR
表示外部.
gsl_odeiv2_step_rk8pd
is defined somewhere in GSL like this:GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk8pd;
, where GSL_VAR
means extern.
我想念什么?
推荐答案
您需要使用vcpkg重新编译gsl源代码.vcpkg可以使用CMake自动编译gsl.请google vcpkg.这很容易,没有错误.
you need re-compile the gsl source codes using vcpkg .vcpkg can compile gsl automatically with CMake. Please google vcpkg. it is very easy and no mistakes.
这篇关于Windows上的GSL链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!