未定义的引用C ++ [英] Undefined reference C++
本文介绍了未定义的引用C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图编译我的第一个合法程序,我从Java转换(我运行测试hello世界类型程序来检查我的编译器,它的工作原理)。
有三个文件:
I'm trying to compile my first legit program that I'm converting from Java (I ran a test hello world type program to check my compiler and it works). There are three files:
main.cpp
#include <iostream>
#include "skewNormal.h"
using namespace std;
double getSkewNormal(double, double);
int main(int argc, char **argv) {
cout << getSkewNormal(10.0, 0.5) << endl;
}
skewNormal.cpp
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
#include <skewNormal.h>
double SkewNormalEvalutatable::evaluate(double x)
{
return 1 / sqrt(2 * M_PI) * pow(M_E, -x * x / 2);
}
SkewNormalEvalutatable::SkewNormalEvalutatable()
{
}
double sum (double start, double stop,
double stepSize,
Evaluatable evalObj)
{
double sum = 0.0, current = start;
while (current <= stop) {
sum += evalObj.evaluate(current);
current += stepSize;
}
return(sum);
}
double integrate (double start, double stop,
int numSteps,
Evaluatable evalObj)
{
double stepSize = (stop - start) / (double)numSteps;
start = start + stepSize / 2.0;
return (stepSize * sum(start, stop, stepSize, evalObj));
}
double getSkewNormal(double skewValue, double x)
{
SkewNormalEvalutatable e;
return 2 / sqrt(2 * M_PI) * pow(M_E, -x * x / 2) * integrate(-1000, skewValue * x, 10000, e);
}
skewNormal.h
#ifndef SKEWNORMAL_H_INCLUDED
#define SKEWNORMAL_H_INCLUDED
class Evaluatable {
public:
virtual double evaluate(double x);
};
class SkewNormalEvalutatable : Evaluatable{
public:
SkewNormalEvalutatable();
double evaluate(double x);
};
double getSkewNormal(double skewValue, double x);
double integrate (double start, double stop, int numSteps, Evaluatable evalObj);
double sum (double start, double stop, double stepSize, Evaluatable evalObj);
#endif // SKEWNORMAL_H_INCLUDED
编译产生以下错误: p>
Compiling yielded the following error:
main.cpp:9: undefined reference to `getSkewNormal(double, double)'
我在Ubuntu 10.10上使用Code :: Blocks。
I'm using Code::Blocks on Ubuntu 10.10.
推荐答案
您可以将skewNormal.cpp编译为.o文件,但是在编译main.cpp时不包括它。
You may be compiling skewNormal.cpp to a .o file, but you're not including it when you compile main.cpp.
这篇关于未定义的引用C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文