0

Hello I am getting this Error when I am compiling my 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 file:

#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

my .cpp file:

#include "MyMath.h"    
CMyMath::CMyMath()
{
    printf("constructor called\n");
}   
CMyMath::~CMyMath()
{
    printf("destructor called\n");
}
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;
}

What do you think where should be a mistake? I am new in C++ and I have really no idea what`s wrong. What do you suggest?

1
  • 4
    std::vector<double> melFilterBank is missing the class qualifier CMyMath:: Commented Mar 21, 2015 at 19:48

2 Answers 2

1

The definition (in the .cpp file) needs to specify that you're defining the member function, not a separate non-member function:

std::vector<double> CMyMath::melFilterBank(std::vector<double> ourSignal, int frequency, int bandNum, int coefNum)
                    ^^^^^^^^^
Sign up to request clarification or add additional context in comments.

Comments

1
std::vector<double> CMyMath :: melFilterBank(std::vector<double> ourSignal, int frequency, int bandNum, int coefNum)

Member Funtion while defining needs to be prefixed with class name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.