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

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You problem is probably session related. Are you creating and… May 16, 2026 at 6:15 pm
  • Editorial Team
    Editorial Team added an answer They do 3 different things: Int32.Parse() expects a string which… May 16, 2026 at 6:15 pm
  • Editorial Team
    Editorial Team added an answer The first thing you should do is get a tool… May 16, 2026 at 6:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Fire up your firebug console and try this out. Compare this: $('body').data('x',1); $(thisx).remove(); console.log($('body').data('x'));
I am the new maintainer for an in-house Python system that uses a set
I'm trying to build cairo on Windows using MinGW (and MSYS). I am following
I've been trying to learn ANTLR and get it working with C output code
I am creating a utility which depends on libassuan aside other depends. While these
I need to write a templated function replace_all in C++ which will take a
I am using Oracle 11g client, with ODP.NET. I am trying to add conditional
From my understanding Sizzle returns an array of objects (DOMElements), I am trying to
I'm trying to link my mac application to the wonderful libancillary library. However, I
I am trying to implement a program which calculates the mean and moment by

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.