首页 文章

在Linux中链接SFML音频?

提问于
浏览
1

当我想使用时,我需要链接哪些库

if(! sb.loadFromFile("Intro.wav")){
    exit(-1);
}
intro.setBuffer(sb);
intro.setLoop(true);
intro.play();

我试过了

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio  Menu.o

但是编译器会抛出错误

undefined reference to `sf::SoundBuffer::SoundBuffer()'
undefined reference to `sf::Sound::Sound()'

1 回答

  • 0

    链接顺序很重要 .

    我倾向于遵循“依赖”规则 . 如果X依赖于Y,则X必须在Y之前 . 所有SFML模块都依赖于SFML系统模块,因此系统模块需要最后 . 另外,您的目标文件依赖于SFML,因此它们需要在SFML库之前 .

    g++ main.o Menu.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-system
    

相关问题