Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 997141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:59:08+00:00 2026-05-16T06:59:08+00:00

This question is as a result of Undefined reference question . When I try

  • 0

This question is as a result of Undefined reference question.

When I try compiling this:

#include "OriAudioCache.hpp"

    int main()
    {
        System *audioSystem(0);
        FMOD_RESULT result;
        result = System_Create(&audioSystem);
        FMOD_CHECK_STATE(result);
        OriAudioCache cache(audioSystem, 20);
        string title("Ambitious Girl");
        string path("/home/findrzkeeprz/Desktop/Resources/The_Ambitious_Girl.mp3");
        cache.LoadSound(title, path, Default);
        vector<OriSound>::iterator v_iter(cache.FindSound(title));
        cache.PlaySound(v_iter->sound());
    }

which uses these files (directly or indirectly):
OriAudioCache.hpp

#ifndef ORI_AUDIO_CACHE_HPP_
#define ORI_AUDIO_CACHE_HPP_

#include "OriSound.hpp"
#include "OriChannel.hpp"

class OriAudioCache
{
    public:
         OriAudioCache(System *audioSystem, int maxChannels);

        ~OriAudioCache()
        {
            vector<OriSound>::iterator v_iter(audioCache_.begin());
            for(; v_iter != audioCache_.end(); ++v_iter)
            {
                v_iter->~OriSound();
            }
                delete audioSystem_;
        }

        void LoadSound(string const& title, string const& path, AudioLoadMode mode);
        vector<OriSound>::iterator FindSound(string const& title);
        void RemoveSound(string const& title);
        void PlaySound(Sound* sound);
        vector<OriChannel>::iterator RequestChannel(bool &allocStatus, FMOD_CHANNELINDEX &allocMode);
        void ReleaseChannel(Channel *channel);

    private:
        void inline SortChannels() {sort(channels_.begin(),channels_.end());}

        vector<OriSound> audioCache_;
        vector<OriChannel> channels_;
        System *audioSystem_;
};

#endif

OriAudioCache.cpp

#include "OriAudioCache.hpp"

OriAudioCache::OriAudioCache(System *audioSystem, int maxChannels)
        :audioSystem_(audioSystem), channels_(maxChannels){}

void OriAudioCache::LoadSound(string const& title, string const& path, AudioLoadMode mode)
{
    OriSound sound(title, path, audioSystem_, mode);
    vector<OriSound>::iterator pos =lower_bound(audioCache_.begin(), audioCache_.end(), sound);
    audioCache_.insert(pos, sound);
}

vector<OriSound>::iterator OriAudioCache::FindSound(string const& title)
{
    vector<OriSound>::iterator v_iter(audioCache_.begin());
    for(; v_iter != audioCache_.end(); ++v_iter) //Would better if I could use a binary search here
    {
        if(v_iter->title() == title) return v_iter;
        else continue;
    }
    return audioCache_.end(); 
}
void OriAudioCache::RemoveSound(string const& title)
{
    vector<OriSound>::iterator v_iter(audioCache_.begin());
    for(; v_iter != audioCache_.end(); ++v_iter) //Would better if I could use a binary search here
    {
        if(v_iter->title() == title) audioCache_.erase(v_iter);
        else continue;
    }
}

void OriAudioCache::PlaySound(Sound* sound)
{
    bool channelAlloc(false);
    FMOD_CHANNELINDEX allocMode = FMOD_CHANNEL_FREE;
    vector<OriChannel>::iterator oriChannel = RequestChannel(channelAlloc, allocMode);
    if(channelAlloc)
    {
        FMOD_RESULT result;
        Channel *chnl = oriChannel->channel();
        result = audioSystem_->playSound(allocMode, sound, false, &chnl);
        FMOD_CHECK_STATE(result);
        bool isPlaying(false);
        chnl->isPlaying(&isPlaying);

        while(isPlaying)
        {
            chnl->isPlaying(&isPlaying);
        }

        bool paused(false);
        chnl->getPaused(&paused);
        if(!paused)
        {
            ReleaseChannel(chnl);
        }
        SortChannels(); //sort channels, reoder for channel requests
    }
}

vector<OriChannel>::iterator OriAudioCache::RequestChannel(bool &allocStatus, FMOD_CHANNELINDEX &allocMode)
{
    vector<OriChannel>::iterator vOri_iter(channels_.begin());
    if(vOri_iter->status() == false)
    {
        if(vOri_iter->channel() == 0) 
        {
            allocMode = FMOD_CHANNEL_FREE;
            vOri_iter->setStatus(true); // flag channel as being used
            return vOri_iter;
        }
        else allocMode = FMOD_CHANNEL_REUSE;
        vOri_iter->setStatus(true); // flag channel as being used
        return vOri_iter;
    }
    else return channels_.end();
}

void OriAudioCache::ReleaseChannel(Channel *channel)
{
    bool playing(false);
    bool paused(false);
    channel->isPlaying(&playing);
    channel->getPaused(&paused);
    if(!playing && !paused)
    {
        vector<OriChannel>::iterator vOri_iter(channels_.begin());
        for(; vOri_iter != channels_.end(); ++vOri_iter)
        {
            if(vOri_iter->channel() == channel) vOri_iter->setStatus(false);
        }
    }
}

OriSound.hpp

#ifndef ORI_SOUND_HPP_
#define ORI_SOUND_HPP_

#include "Public/ThirdParty.hpp"
#include "Public/Public.hpp"

class OriSound
{
    public:
        OriSound()
            :title_(), path_(), sound_(0)
        {}

        OriSound(string const& title, string const& path, System* const& audioSystem, AudioLoadMode mode)
            : title_(title), path_(path)
        {
            FMOD_RESULT result;
            audioSystem->createSound(path.c_str(), mode, 0, &sound_);
            FMOD_CHECK_STATE(result);
        }

        ~OriSound()
        {
            delete sound_;
        }

        string title() const { return title_;}
        string path() const {return path_;}
        Sound *sound() const {return sound_;}

    private:
        string title_;
        string path_;
        Sound *sound_;
};

bool operator<(OriSound const& lhs, OriSound const& rhs)
{
    int result = (lhs.title()).compare(rhs.title());
    if(result == 0) return false;
    else if(result < 0 ) return true;
    else return false;
}
#endif

OriChannel.hpp

#ifndef ORI_CHANNEL_HPP_
#define ORI_CHANNEL_HPP_

#include "Public/Public.hpp"

class OriChannel
{
    public:
        OriChannel()
            :status_(false), channel_(0)
        {}

        bool status() const {return status_;}
        Channel* channel() const {return channel_;}
        void setStatus(bool value) { status_ = value;}

    private:
        bool status_;
        Channel *channel_;
};

bool operator<(OriChannel const& lhs, OriChannel const& rhs)
{
    return lhs.status() < rhs.status();
}


#endif

Public.hpp

#ifndef PUBLIC_HPP_
#define PUBLIC_HPP_

#include <algorithm>
#include <iostream>
#include <istream>
#include <ostream>
#include <vector>

using namespace std;

#endif

ThirdParty.hpp

#ifndef THIRD_PARTY_HPP_
#define THIRD_PARTY_HPP_

#include "FMODEX/fmod_errors.h"
#include "FMODEX/fmod.hpp"

#include "Public/Public.hpp"

using namespace FMOD;

void FMOD_CHECK_STATE(FMOD_RESULT result)
{
    if (result != FMOD_OK)
    {
        cout << "FMOD error! (" << result << ")" << FMOD_ErrorString(result) << endl;
        exit(-1);
    }
}

typedef enum
{
    Default = FMOD_DEFAULT,
    Hardware_2D_CreateStream = FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM ,
    Hardware_2D_CreateSample = FMOD_HARDWARE | FMOD_2D | FMOD_CREATESAMPLE,
    Hardware_3D_CreateStream = FMOD_HARDWARE | FMOD_3D | FMOD_CREATESTREAM ,
    Hardware_3D_CreateSample = FMOD_HARDWARE | FMOD_3D | FMOD_CREATESAMPLE,
    Software_2D = FMOD_SOFTWARE | FMOD_2D,
    Software_2D_CreateStream = FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM ,
    Software_2D_CreateSample = FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESAMPLE,
    Software_2D_CreateCompressedSample = FMOD_SOFTWARE | FMOD_2D | FMOD_CREATECOMPRESSEDSAMPLE,
    Software_3D_CreateStream = FMOD_SOFTWARE | FMOD_3D | FMOD_CREATESTREAM ,
    Software_3D_CreateSample = FMOD_HARDWARE | FMOD_3D | FMOD_CREATESAMPLE,
    Software_3D_CreateCompressedSample = FMOD_SOFTWARE | FMOD_3D | FMOD_CREATECOMPRESSEDSAMPLE
}AudioLoadMode;
#endif

I get multiple definition errors:

findrzkeeprz@Aardvak:~/Documents/Chidori/Engine/Audio$ make
g++ -ggdb -I../../ -I../../Engine -I../../Include -I../../Public -o audio OriAudioCache.cpp main.cpp ../../Libraries/FMODEX/libfmodex.so
/tmp/ccWiUARs.o: In function `FMOD_CHECK_STATE(FMOD_RESULT)':
/home/findrzkeeprz/Documents/Chidori/Engine/Audio/../../Public/ThirdParty.hpp:12: multiple definition of `FMOD_CHECK_STATE(FMOD_RESULT)'
/tmp/ccF7Dod3.o:/home/findrzkeeprz/Documents/Chidori/Engine/Audio/../../Public/ThirdParty.hpp:12: first defined here
/tmp/ccWiUARs.o: In function `operator<(OriSound const&, OriSound const&)':
/home/findrzkeeprz/Documents/Chidori/Engine/Audio/OriSound.hpp:38: multiple definition of `operator<(OriSound const&, OriSound const&)'
/tmp/ccF7Dod3.o:/home/findrzkeeprz/Documents/Chidori/Engine/Audio/OriSound.hpp:38: first defined here
/tmp/ccWiUARs.o: In function `operator<(OriChannel const&, OriChannel const&)':
/home/findrzkeeprz/Documents/Chidori/Engine/Audio/OriChannel.hpp:23: multiple definition of `operator<(OriChannel const&, OriChannel const&)'
/tmp/ccF7Dod3.o:/home/findrzkeeprz/Documents/Chidori/Engine/Audio/OriChannel.hpp:23: first defined here
collect2: ld returned 1 exit status
make: ***  Error 1

What I’m I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:59:09+00:00Added an answer on May 16, 2026 at 6:59 am

    Your

    bool operator<(OriSound const& lhs, OriSound const& rhs)
    

    function needs to be marked inline or it needs to be implemented in a .cpp with only the declaration inthe .hpp file.

    inline
    bool operator<(OriSound const& lhs, OriSound const& rhs)
    {
        // ....
    }
    

    or:

    // in OriSound.hpp
    bool operator<(OriSound const& lhs, OriSound const& rhs);
    
    // in OriSound.cpp
    bool operator<(OriSound const& lhs, OriSound const& rhs)
    {
        // ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is a result of what i noticed while trying to answer another
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
I think this must be a stupid question, but why do the results of
This question is kind of an add-on to this question In C#, a switch
This question and answer shows how to send a file as a byte array
This question comes on the heels of the question asked here . The email
This question would probably apply equally as well to other languages with C-like multi-line
This question is a follow up to my previous question about getting the HTML
(This question is over 6 years old and probably no longer has any relevance.)
This question is about removing sequences from an array, not duplicates in the strict

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.