首页 > 解决方案 > 出现错误:尝试加载 .ogg 文件时出现“对 `__imp__ZN2sf5 的未定义引用”

问题描述

我已经搜索了很多,特别是在加载 .OGG 文件的编码上没有运气。我正在尝试添加 .ogg 格式的音频文件,但不知道问题出在哪里。

这是我将 .OGG 音频文件添加到项目中的步骤:

  1. 我首先将它添加到项目中的音频资产中。当我打开 .OGG 文件时,我收到警告/错误: 在此处输入图像描述 如果这很重要,我应该以什么编码加载 .OGG 文件?

    • 我试图选择一个没有给我警告的编码,它是“ISO-8859-1”。请注意,我尝试了其他编码,例如 UTF-8、UTF-16、UTF-32、US-ASCII,但没有任何效果。

这是 UTF-8 编码(默认)的 .OGG 文件的图片: 在此处输入图像描述

  1. 我使用 SFML 将声音文件加载到我选择调用 Sound 的类中:

声音.cpp:

#include "Sound.h"

Sound::Sound() {
    const std::string pathToProject = "C:\\Users\\User\\projectName";

    exSongbuffer.loadFromFile(pathToProject + "\\projectContainer\\Assets\\Sounds\\ExampleSound.ogg");
        exampleSong.setBuffer(exSongbuffer);
    }

声音.h:

#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>

class Sound {
public:
    Sound();

    sf::Sound ExampleSound;
    sf::SoundBuffer exSoundBuffer;
}

配置.h:

class Configuration {
public:
    Sound* sound = new Sound();
}

机器.cpp:

StateMachine::StateMachine() {
    auto* sound = new Sound();
    config.sound = sound;
    sound->menuSong.play();
}

主.cpp:

int main() {
   StateMachine stateMachine;
   while (stateMachine.run()) { // run() just runs the program until the user exits.

   }
}    

这是我尝试运行程序时的错误消息:

在此处输入图像描述

标签: c++clionogg

解决方案


推荐阅读