C++代码中存在未定义的引用错误
Undefined reference error in C++ code
你好,我在编译代码时收到此错误:
main.cpp:(.text.startup+0xfc): undefined reference to `CMyMath::melFilterBank(std::vector<double, std::allocator<double> >, int, int, int)'
collect2: error: ld returned 1 exit status
make: *** [bin/main.elf] Error 1
my.h文件:
#ifndef _MYMATH_H_
#define _MYMATH_H_
#define _USE_MATH_DEFINES
#include <vector>
#include <stdio.h>
#include <cmath>
#include <stdint.h>
#include <complex>
class CMyMath
{
public:
CMyMath();
~CMyMath();
std::vector<double> melFilterBank(std::vector<double> signal, int frequency, int band_num, int coef_num);
};
#endif
我的.cpp文件:
#include "MyMath.h"
CMyMath::CMyMath()
{
printf("constructor calledn");
}
CMyMath::~CMyMath()
{
printf("destructor calledn");
}
std::vector<double> melFilterBank(std::vector<double> ourSignal, int frequency, int bandNum, int coefNum)
{
std::vector<double> output; //ck in matlab code
/*
DO SOME STUFF
*/
return output;
}
main:
#include <stdio.h>
#include <vector>
#include <cmath>
#include "MyMath.h"
int main()
{
class CMyMath a;
std::vector<double> mel {0.0000001,0.0000005,0.0000004,0.0000005};
a.melFilterBank(mel,8000,6,5);
return 0;
}
你认为哪里应该出错?我是C++的新手,我真的不知道出了什么问题。你有什么建议?
定义(在.cpp
文件中)需要指定您定义的是成员函数,而不是单独的非成员函数:
std::vector<double> CMyMath::melFilterBank(std::vector<double> ourSignal, int frequency, int bandNum, int coefNum)
^^^^^^^^^
std::vector<double> CMyMath :: melFilterBank(std::vector<double> ourSignal, int frequency, int bandNum, int coefNum)
定义时,成员函数需要以类名为前缀。
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 只有级联分类器会发出未定义的引用错误
- 2个模板化类的非模板友元函数未定义引用错误
- C/C++ 取消引用错误:在空检查之前取消引用
- 为什么我的C++代码无法编译,出现未定义的引用错误
- 我的代码中C++未定义的引用错误?
- 模板专用化会导致未定义的引用错误
- .cpp文件中未定义的引用错误
- c++ 中目录中文件的未定义引用错误
- Opencv4 使用 pkg-config 给出未定义的引用错误
- 使用Cygwin C++时出现未定义的引用错误,为什么我的文件没有链接?
- 共享指针取消引用错误
- 编译简单的多文件类程序时出现未定义的引用错误
- 模板函数产生未定义的引用错误
- 调用提取重加载器会产生对"运算符"的未定义引用错误>>
- 如何修复"未定义的引用"错误 opencv 和 g++
- 未定义的引用错误,我该怎么办?