0

I have the type of parameters as

typedef double DP;
typedef const NRVec<DP> Vec_I_DP; //NRVec is a parametrized template class.
typedef NRVec<DP> Vec_DP, Vec_O_DP, Vec_IO_DP;

xa -> Vec_I_DP(30)
ya -> Vec_I_DP(30)
yp1 -> DP(30)
ypn -> DP(30)
y2 -> Vec_O_DP(30)

My function call is

NR::spline(xa,          ya,          yp1,          ypn,         y2);

And the function declaration is

void spline(Vec_I_DP &x, Vec_I_DP &y, const DP yp1, const DP ypn,Vec_O_DP &y2);

Can somebody tell me, why I get the following error.

1>Hiwi.obj : error LNK2019: unresolved external symbol "void __cdecl NR::spline(class NRVec<double> const &,class NRVec<double> const &,double,double,class NRVec<double> &)" (?spline@NR@@YAXABV?$NRVec@N@@0NNAAV2@@Z) referenced in function "void __cdecl smooth_Line(double *,int *,int,int,double *,double *,int,int)" (?smooth_disp_Line@@YAXPANPAHHH00HH@Z)
asit_dhal
  • 1,239
  • 19
  • 35
  • What are the macros Vec_I_DP and Vec_O_DP? – The Light Spark Nov 09 '15 at 15:58
  • The problem seems to be related to linking, not template instantiation. Did you define the function `NR::spline`? Did you include the file in which the function is defined to the project/makefile? – R Sahu Nov 09 '15 at 16:03
  • 2
    Where is the function defined? Are you linking against it? Please check through this: [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – NathanOliver Nov 09 '15 at 16:03

1 Answers1

0

It seems you are using NR2. The newest version is NR3 which defines spline in a class called Spline_interp. You should use NR3. For this matter, I will show you an example for using the aforementioned class. Let's say you have five values for sin(x) and you can to interpolate these values and acquire the interpolated values, say sin(x=.25). In this example, we know true value, therefore, we can compare the result with the interpolated value. In the following code, I got the interpolated value plus the error.

#include <iostream>
#include <iomanip>
#include "nr3.h"
#include "interp_1d.h" 

int main() {
    VecDoub x(5), y(5);

    //x = 0:0.3:1
    //y = sin(x)

    x[0] = 0.0;
    x[1] = 0.3;
    x[2] = 0.6;
    x[3] = 0.9;

    y[0] = 0.0;
    y[1] = 0.2955;
    y[2] = 0.5646;
    y[3] = 0.7833;

    /**************************************************
        3.3 Cubic Spline Interpolation
        page(120)
    ***************************************************/

    Spline_interp myfunc3(x,y);
    std::cout << "Cubic Spline Interpolation: " << std::endl;
    std::cout << "interp value: " << myfunc3.interp(.25)  << "\n" 
              << "  true value: " << sin(0.25)            << "\n" 
              << "       error: " << ( ( sin(0.25) - myfunc3.interp(.25) )/sin(0.25) )*100.0  << "%" << std::endl;


    std::cout << std::setw(25) << std::cout.fill('=') << std::endl; 


    return 0;
} 

For compilation in Windows from the command prompt,

cl /EHsc main.cpp /Fetest.exe /I path\to\NR\code

The result is

Cubic Spline Interpolation:
interp value: 0.247187
  true value: 0.247404
       error: 0.0876794%
========================

The error is very small.

CroCo
  • 5,531
  • 9
  • 56
  • 88
  • If you really want to use NR2, notify me so that I can post an answer regarding this matter, however, I highly recommend you to use NR3 – CroCo Jan 25 '16 at 15:16