2

我有以下功能(在 dm.cpp 中)

#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <Eigen/Dense>
#include "dm.hpp";//calculateStdDev() is declared in the header

double calculateStdDev(const Eigen::VectorXf& input, unsigned int count, double& mean, double& variance, double& stddev) {
    double M = input(0);
    double Q = 0.0;
    for (unsigned int k = 1 ; k < count ; k++) {
        double del = input(k) - M;
        unsigned int j = k + 1;
        Q += k * (del * del) / j;
        M += del / j;
    }
    variance = Q / (count - 1);
    stddev = std::sqrt(variance);
    mean = M;
    return stddev;
}

它在我的程序 test.cpp 中被调用,如下所示:

#include <iostream>
#include <iterator>

#include <Eigen/Dense>
#include "dm.hpp"
void regressor::operator()(void) {

    unsigned int rows;
    double meanR, varR, stddevR;
    Eigen::MatrixXf A(rows, cols);
    Eigen::VectorXf b(rows),res(rows);

    for (unsigned int k = 0 ; k < rows; k++) {
        for (unsigned int j = 0 ; j < cols ; j++) {
            A(k,j) = Xb[k][j];
        }
    }
    beta = A.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b);
    res = A * beta - b;

    calculateStdDev(res,rows,meanR,varR,stddevR);
}

我收到以下错误:

In function `regressor::operator()()':
../../src/algo/test.cpp:55: undefined reference to `calculateStdDev(Eigen::Matrix<float, -1, 1, 0, -1, 1> const&, unsigned int, double&, double&, double&)'
collect2: ld returned 1 exit status

我的操作系统是 ubuntu (v.10),当在 cygwin 上运行完全相同的程序时,它可以工作。这是否意味着这是一个 GCC 问题。如果是这样,任何人都可以建议如何解决它。

编辑:我正在运行以下内容:

g++ test.cpp dm.cpp main.cpp -o et -lboost_date_time -lgsl -lgslcblas
4

0 回答 0