【问题标题】:Undefined symbols for architecture x86_64: "alglib::spline2dcalc(alglib::spline2dinterpolant const&, double, double, alglib::xparams)" [duplicate]架构 x86_64 的未定义符号:“alglib::spline2dcalc(alglib::spline2dinterpolant const&, double, double, alglib::xparams)” [重复]
【发布时间】:2018-08-15 08:21:47
【问题描述】:
#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

要运行代码,它就像 eroor 一样 架构 x86_64 的未定义符号:

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

我怎样才能让它工作?

【问题讨论】:

  • 可能您需要链接库,仅包含标头是不够的,或者如果它仅包含标头库,您需要为特定环境定义宏

标签: c++ macos alglib


【解决方案1】:

您缺少适当的 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

【讨论】:

  • 这些真的很管用,谢谢你解决了我的问题!
猜你喜欢
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多