gpt4 book ai didi

c++ - 未定义的引用问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:36:26 25 4
gpt4 key购买 nike

当我尝试编译时:

#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());
}

它使用这些文件: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);
}
}
}

我收到 undefined reference 错误:

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_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, AudioLoadMode)'
/home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:13: undefined reference to `OriAudioCache::FindSound(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/findrzkeeprz/Documents/Chidori/Engine/Audio/main.cpp:14: undefined reference to `OriAudioCache::PlaySound(FMOD::Sound*)'
collect2: ld returned 1 exit status
make: *** [audio] Error 1

我在这里做错了什么?

最佳答案

你正在编译 OriAudioCache.hpp,当你应该编译 OriAudioCache.cpp 时,假设该文件包含实现。

关于c++ - 未定义的引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3495422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com