Quand j’essaye de comstackr ceci:
#include "OriAudioCache.hpp" int main() { System *audioSystem(0); FMOD_RESULT result; result = System_Create(&audioSystem); FMOD_CHECK_STATE(result); OriAudioCache cache(audioSystem, 20); ssortingng title("Ambitious Girl"); ssortingng path("/home/findrzkeeprz/Desktop/Resources/The_Ambitious_Girl.mp3"); cache.LoadSound(title, path, Default); vector::iterator v_iter(cache.FindSound(title)); cache.PlaySound(v_iter->sound()); }
Qui utilise ces fichiers: 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::iterator v_iter(audioCache_.begin()); for(; v_iter != audioCache_.end(); ++v_iter) { v_iter->~OriSound(); } delete audioSystem_; } void LoadSound(ssortingng const& title, ssortingng const& path, AudioLoadMode mode); vector::iterator FindSound(ssortingng const& title); void RemoveSound(ssortingng const& title); void PlaySound(Sound* sound); vector::iterator RequestChannel(bool &allocStatus, FMOD_CHANNELINDEX &allocMode); void ReleaseChannel(Channel *channel); private: void inline SortChannels() {sort(channels_.begin(),channels_.end());} vector audioCache_; vector channels_; System *audioSystem_; }; #endif
et OriAudioCache.cpp
#include "OriAudioCache.hpp" OriAudioCache::OriAudioCache(System *audioSystem, int maxChannels) :audioSystem_(audioSystem), channels_(maxChannels){} void OriAudioCache::LoadSound(ssortingng const& title, ssortingng const& path, AudioLoadMode mode) { OriSound sound(title, path, audioSystem_, mode); vector::iterator pos =lower_bound(audioCache_.begin(), audioCache_.end(), sound); audioCache_.insert(pos, sound); } vector::iterator OriAudioCache::FindSound(ssortingng const& title) { vector::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(ssortingng const& title) { vector::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::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::iterator OriAudioCache::RequestChannel(bool &allocStatus, FMOD_CHANNELINDEX &allocMode) { vector::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::iterator vOri_iter(channels_.begin()); for(; vOri_iter != channels_.end(); ++vOri_iter) { if(vOri_iter->channel() == channel) vOri_iter->setStatus(false); } } }
Je reçois des erreurs de référence non définies:
findrzkeeprz@Aardvak:~/Documents/Chidori/Engine/Audio$ make g++ -ggdb -I../../ -I../../Engine -I../../Include -I../../Public -o audio main.cpp ../../Libraries/FMODEX/libfmodex.so /tmp/cctNhPVy.o: In function `main': /home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:9: undefined reference to `OriAudioCache::OriAudioCache(FMOD::System*, int)' /home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:12: undefined reference to `OriAudioCache::LoadSound(std::basic_ssortingng<char, std::char_traits, std::allocator > const&, std::basic_ssortingng<char, std::char_traits, std::allocator > const&, AudioLoadMode)' /home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:13: undefined reference to `OriAudioCache::FindSound(std::basic_ssortingng<char, std::char_traits, std::allocator > const&)' /home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:14: undefined reference to `OriAudioCache::PlaySound(FMOD::Sound*)' collect2: ld returned 1 exit status make: *** Error 1
Qu’est-ce que je fais mal ici?
Vous comstackz OriAudioCache.hpp, alors que vous devriez comstackr OriAudioCache.cpp, en supposant que le fichier qui contient l’implémentation.
En général, le terme “référence non définie” provenant d’un compilateur (en réalité, l’éditeur de liens) signifie qu’un fragment de code accède à un symbole que l’éditeur de liens n’a pas pu trouver.
namespace
). La plupart des cas de ces erreurs ne concernent pas l’opérateur de référence C ++ ni les pointeurs de déréférencement.