0

so Im quite new to c++ and I struggle to find an answer to my problem. Im using VS Code and I would like to know a way to create a resource from wav file and play it using PlaySound. I have no idea how to adress a resource.

I tried making header file defining IDR_SOUND 1 and including it in .rc file but when compiling it with g++ it just gives me an error: "error: ld returned 1 exit status"

#include "resource.h"

IDR_SOUND           WAVE            "C:\Users\super\sound.wav"

My code looks like this:

#include <windows.h>
#include "resource.h"
#pragma comment(lib, "winm.lib")

int main()
{
    PlaySound(MAKEINTRESOURCE(IDR_SOUND), GetModuleHandle(NULL), SND_RESOURCE);
    std::cin.get();
}

I would be really thankful for any explanation how to do it properly

Goh
  • 13
  • 2
  • please provide the full error output from the linker. I'd recommend using visual studio on windows, its much simpler to setup than visual studio code – Alan Birtles Nov 28 '20 at 17:23
  • sure, the full error is: "c:/program files/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\super\AppData\Local\Temp\ccrXOddv.o:main.cpp:(.text+0x3f): undefined reference to `__imp_PlaySoundA' collect2.exe: error: ld returned 1 exit status" – Goh Nov 28 '20 at 17:42
  • Also anything for VS is fine too, but i find VS Code much simplier to use and manage – Goh Nov 28 '20 at 17:44
  • you need to link to [winmm.lib](https://docs.microsoft.com/en-us/previous-versions/dd743680(v=vs.85)) – Alan Birtles Nov 28 '20 at 17:59
  • how to link it? Doing: #pragma comment(lib, "Winmm.lib") gives same error – Goh Nov 28 '20 at 18:06
  • I don't think GCC supports [`#pragma comment(lib`](https://stackoverflow.com/questions/1685206/pragma-commentlib-xxx-lib-equivalent-under-linux) you really would be better off with visual studio if you're a c++ novice – Alan Birtles Nov 28 '20 at 18:21

0 Answers0