我有以下功能(在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(第10版),当在cygwin上运行完全相同的程序时,它可以工作。这是否意味着这是GCC问题。如果是这样,任何人都可以建议如何解决它。
编辑:我正在运行以下内容:
g++ test.cpp dm.cpp main.cpp -o et -lboost_date_time -lgsl -lgslcblas