Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking error on Windows #43

Closed
nromashchenko opened this issue Dec 23, 2019 · 2 comments
Closed

Linking error on Windows #43

nromashchenko opened this issue Dec 23, 2019 · 2 comments
Assignees

Comments

@nromashchenko
Copy link

Hello!
I am trying to compile examples from this page.
Operating system: Windows 10
Compiler: msvs 2019
Build system: cmake
GSL: tried both 2.4 and 2.6 from conda

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_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;
}

I am getting this error:
error LNK2001: unresolved external symbol gsl_odeiv2_step_rk8pd

The same example works fine on Linux.
The basic example from here works fine on Windows, so the problem is just the example above.
Can you please point out what is wrong?
Thanks

@fdabrandao
Copy link
Member

The gsl libraries available from conda are originated from https://github.com/conda-forge/gsl-feedstock, which is using the default build system (see, e.g., https://github.com/conda-forge/gsl-feedstock/blob/master/recipe/build.sh) instead of the cmake build configuration that we provide in this repository.

Did you try building gsl from scratch using the cmake configuration we provide? This may be simply an issue of a non-exported symbol as on Linux with gcc all symbols are exported by default, but with Visual Studio you need to mark the symbols that you want to export with __declspec(dllexport) when building the library, and __declspec(dllimport) when importing.

@nromashchenko
Copy link
Author

nromashchenko commented Jan 6, 2020

Hello! Thanks for the answer.

Did you try building gsl from scratch using the cmake configuration we provide?

Yes, I tried to build it by my own and it works just fine. Seems to be a conda-forge related issue... Thank you anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants