Search code examples
c++sfml

SFML-Audio LNK2001 error, linking error, I linked all the libraries but it doesn't work


when I try to use the SFML-Audio library, I get this error:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: __cdecl sf::SoundBuffer::~SoundBuffer(void)" (__imp_??1SoundBuffer@sf@@QEAA@XZ)   War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::SoundBuffer::loadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?loadFromFile@SoundBuffer@sf@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)  War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: __cdecl sf::SoundBuffer::SoundBuffer(void)" (__imp_??0SoundBuffer@sf@@QEAA@XZ)    War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Sound::setBuffer(class sf::SoundBuffer const &)" (__imp_?setBuffer@Sound@sf@@QEAAXAEBVSoundBuffer@2@@Z)  War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: virtual void __cdecl sf::Sound::play(void)" (__imp_?play@Sound@sf@@UEAAXXZ)   War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::Sound::~Sound(void)" (__imp_??1Sound@sf@@UEAA@XZ) War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: __cdecl sf::Sound::Sound(void)" (__imp_??0Sound@sf@@QEAA@XZ)  War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\main.obj  1   
Error   LNK1120 7 unresolved externals  War-Tech    C:\Users\domon\Documents\myfiless\MyProjects\War-Tech\x64\Release\War-Tech.exe  1   

My included libraries:

sfml-graphics.lib
sfml-window.lib
sfml-system.lib
sfml-audio-s.lib
sfml-system-s.lib
sfml-audio-s-d.lib
openal32.lib
opengl32.lib
winmm.lib

Please help me, I've been struggling with this problem for a long time, I can't seem to get the sound to play in the game.SFML itself works correctly, but for some reason SFML-Audio does not work for me :(

Sound code:

sf::SoundBuffer buffer;

if (!buffer.loadFromFile("main.wav"))
{
    std::cout << "ERROR" << std::endl;
}

sf::Sound sound;

sound.setBuffer(buffer);

sound.play();

Solution

  • Just include sfml-audio.lib instead of sfml-audio-d.lib