CodeBlocks SFML音频库将无法正常工作

时间:2015-07-19 03:22:26

标签: c++ audio codeblocks sfml

我一直在关注代码块中的SFML的一些youtube教程,我们刚刚接触到音频。到目前为止,我只使用了图形方面,但没有任何问题。虽然对于音频,我已经尝试从使用.ogg切换到.wav文件并返回到我的代码中,并在一段时间内使用了所有内容,但该程序无法正常工作。我真的不明白这些库是如何工作的(如果不明显的话我是新的)但是我已经查看了sfml的lib文件并在我的链接器设置中包含了每个文件,所以我不明白为什么我继续得到错误。无论如何,我遇到了大量的错误,并希望简单地使用SFML的音频部分。以下是破解案例所需的所有数据:

实际代码:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <string>
#include <iostream>

int main(){

    sf::Vector2i screenDimensions(800,600);

    sf::RenderWindow Window;
    Window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "A Window");

    sf::Clock clock;

    sf::SoundBuffer soundBuffer;
    sf::Sound sound;

    if(!soundBuffer.loadFromFile("punch.ogg")){
        std::cout << "Can't find audio file" << std::endl;
    }

    sound.setBuffer(soundBuffer);

    float moveSpeed = 10000.0f;

    while(Window.isOpen()){

        clock.restart();
        sf::Event Event;
        while(Window.pollEvent(Event)){

            switch(Event.type){
            case sf::Event::Closed:
                Window.close();
                break;
            case sf::Event::KeyPressed:
                if(Event.key.code == sf::Keyboard::Escape){
                    Window.close();
                }
                if(Event.key.code == sf::Keyboard::P){
                    sound.play();
                }
                break;
            }
        }

        Window.display();
        Window.clear();
        }
}

链接器设置:(我已尝试将订单移动一吨左右,但没有帮助)

sfml-audio-s-d
sfml-network-s-d
sfml-graphics-s-d
sfml-window-s-d
sfml-system-s-d
flac
ogg
vorbis
vorbisenc
vorbisfile
openal32
jpeg
freetype
ws2_32
gdi32
opengl32
winmm

最后,所有的错误:

E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_write' follow|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_readinit'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_readinit'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_read' follow|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_read' follow|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeinit'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeclear'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeclear'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeinit'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_write' follow|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_reset'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeclear'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_reset'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
E:\CODING STUFF FOR C++\zzz.External Libraries\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings (0 minutes, 2 seconds) ===|

提前感谢:)

3 个答案:

答案 0 :(得分:0)

未链接音频库。这是未定义的引用错误的含义。因此,您应该检查您的项目文件是否链接到路径中存在的静态lib文件(.a)。

另一件事是你不需要你的链接器设置中的任何库,除了SFML库之外,因为它们已经链接到SFML静态lib文件中。不是真的在2.3中,但在2.1中是真的

答案 1 :(得分:0)

正确的链接顺序是:

openal32
flac
vorbisenc
vorbisfile
vorbis
ogg

不是:

flac
ogg
vorbis
vorbisenc
vorbisfile
openal32

否则它会为您提供对'oggpack _ ***'的未定义引用

答案 2 :(得分:0)

请使用正确的链接顺序:

def to_var(x, volatile=True):
if torch.cuda.is_available():
    x = x.cuda()
return Variable(x, volatile=volatile)

否:

openal32
flac
vorbisenc
vorbisfile
vorbis
ogg

否则,它将为您提供对'oggpack _ ***'的未定义引用