未定义的体系结构符号 x86_64:"alglib::spline2dcalc(alglib::spline2dinterpolant const&, double, double, alglib::xparams)"

Undefined symbols for architecture x86_64: "alglib::spline2dcalc(alglib::spline2dinterpolant const&, double, double, alglib::xparams)"

#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "interpolation.h"

using namespace alglib;


int main(int argc, char **argv)
{
    //
    // We use bilinear spline to interpolate f(x,y)=x^2+2*y^2 sampled 
    // at (x,y) from [0.0, 0.5, 1.0] X [0.0, 1.0].
    //
    real_1d_array x = "[0.0, 0.5, 1.0]";
    real_1d_array y = "[0.0, 1.0]";
    real_1d_array f = "[0.00,0.25,1.00,2.00,2.25,3.00]";
    double vx = 0.25;
    double vy = 0.50;
    double v;
    double dx;
    double dy;
    double dxy;
    spline2dinterpolant s;

    // build spline
    spline2dbuildbicubicv(x, 3, y, 2, f, 1, s);

    // calculate S(0.25,0.50)
    v = spline2dcalc(s, vx, vy);
    printf("%.4f\n", double(v)); // EXPECTED: 1.0625

    // calculate derivatives
    spline2ddiff(s, vx, vy, v, dx, dy, dxy);
    printf("%.4f\n", double(v)); // EXPECTED: 1.0625
    printf("%.4f\n", double(dx)); // EXPECTED: 0.5000
    printf("%.4f\n", double(dy)); // EXPECTED: 2.0000
    return 0;
}

我想用alglib做双三次样条插值,但是当我用

g++ -I /Users/.../Documents/cpp/src -o a test.cpp

到运行代码,它像一样出现 体系结构的未定义符号 x86_64:

"alglib::spline2dcalc(alglib::spline2dinterpolant const&, double, double, alglib::xparams)", referenced from:
      _main in ccmNfxlB.o

我怎样才能让它发挥作用?

您缺少适当的 ALGLIB 定义。

解决方法:编译ALGLIB的源代码(.h和.cpp文件)形成一个静态库文件,然后在调用g++的时候加上test.cpp 这样编译器就可以找到并使用缺少的定义。

完成步骤:

首先,将所有 ALGLIB 的源文件(.h 和 .cpp 文件)放入一个单独的文件夹中,您应该从中调用:

g++ -c *.cpp
ar rcs alglib.a *.o

然后,将 alglib.a 文件复制到 test.cpp 所在的位置,然后从那里调用再次编译器,但这次是这样的:

g++ -I /Users/.../Documents/cpp/src -o a test.cpp alglib.a