Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this giving me "Undefined references to constructors and destructors"?

Tags:

c++

I have the following pieces of code:

Leomedia.h

#include "MusicMetaDatter.h"

#ifndef LEOMEDIA_H
#define LEOMEDIA_H

namespace Leomedia
{
    typedef enum
    {
        read,
        write
    } FileMode;
}

#endif // LEOMEDIA_H

MusicMetaDatter.h

#ifndef MUSICMETADATTER_H
#define MUSICMETADATTER_H

#include "Leomedia.h"
#include <string>

/**
* METADATTER
* @Version 1.0.0a
* @Author: Sergio Andrés Ibañez (Leonnears)
* @Twitter: Leonnears
* @Package: Leomedia
*/

    namespace Leomedia
    {
        typedef enum
        {
            mp3,
            m4a,
            flac,
            ape,
            wavPack,
            aiff,
            wav,
            ogg,
            tta
        } AudioFileType;

        class MusicMetaDatter
        {
            public:
                MusicMetaDatter(std::string fileName, AudioFileType type, FileMode mode);
                virtual ~MusicMetaDatter();

            private:
                std::string md_fileName;
                AudioFileType md_fileType;
                FileMode md_fileMode;
        };
    }

    #endif // MUSICMETADATTER_H

MusicMetaDatter.cpp

#include "MusicMetaDatter.h"
#include <string>

Leomedia::MusicMetaDatter::MusicMetaDatter(std::string fileName, AudioFileType type, FileMode mode)
{
    this -> md_fileName = fileName;
    this -> md_fileType = type;
    this -> md_fileMode = mode;
}

Leomedia::MusicMetaDatter::~MusicMetaDatter()
{
    //dtor
}

MetaDatterTest.cpp

#include <iostream>
#include "Leomedia.h"
#include <string>
using namespace std;

int main()
{
    Leomedia::MusicMetaDatter meta("troll", Leomedia::mp3, Leomedia::read);
    return 0;
}

When I compile MetaDatterTest I get the following errors:

undefined reference to Leomedia::MusicMetaDatter::MusicMetaDatter(std::string, Leomedia::AudioFileType, Leomedia::FileMode)' undefined reference to Leomedia::MusicMetaDatter::~MusicMetaDatter()' undefined reference to Leomedia::MusicMetaDatter::~MusicMetaDatter()'

All the files are in the same directory. I'm using mingw 4.4.1

Can someone help me with this? It has dumbfounded me beyond understanding.

like image 275
Andy Ibanez Avatar asked Dec 01 '11 18:12

Andy Ibanez


2 Answers

You haven't given your compile command, but I suspect it lacks MusicMetaDatter.cpp in it.

Should be something like

g++ -o MetaDatterTest MetaDatterTest.cpp MusicMetaDatter.cpp 
like image 115
Michael Krelin - hacker Avatar answered Sep 20 '22 17:09

Michael Krelin - hacker


Those are linker errors. It compiled just fine. When you link it, you'll need to link to the code that contains the destructor for MusicMetaDatter or you'll get that error.

like image 32
David Schwartz Avatar answered Sep 23 '22 17:09

David Schwartz