Play a music file in C++ program being compiled by MinGW

dabadee

I'm using the minGW compiler to make a C++ program that plays a song file in loop in the background for a game. I pass this into the command prompt : D:\project g++ music.cpp

And the error I get is:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\ccQ5qzuQ.o:music.cpp:(.text+0x2e): undefined reference to `PlaySoundA@12' collect2.exe: error: ld returned 1 exit status**

What am I doing wrong? I can't find any clear explanation for this for minGW (not visual studio). Any help is appreciated!!

The code is:

#include <iostream>
#include <windows.h>

int main() {
  PlaySound(TEXT("blue.wav"), NULL, SND_SYNC);
  system("pause");
  return 0;
}```

ryyker

The "undefined reference to PlaySoundA suggests that you are not including the right library into your project. It requires: Mmsystem.h (include Windows.h) Winmm.lib Winmm.dll.

read more here

Steps to add a library in Code::Blocks are:

  • Choose Project, Build Options.
  • Click the Linker Settings tab. Click the Add button. ...
  • Select the library file and click the Open button. Click No to avoid using a relative path.
  • Click OK to add the library to the list. ...
  • Choose File, Save Project.

Make sure the .dll is included in your path environment variable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Include mingw libraries in compiled file

From Dev

Distribute a program compiled with MinGW g++

From Dev

Segmentation fault trying to execute a MinGW compiled C++ winapi test program

From Dev

if 0 is compiled in c program

From Dev

Play invisible music with batch file?

From Dev

play music in sdcard if exist file

From Dev

Play music file using Batch?

From Dev

Compiled c++ output file displays random character at end of program?

From Dev

C program compiled in cygwin with make: "cannot execute binary file"

From Java

Program being compiled differently in 3 major C++ compilers. Which one is right?

From Dev

How is a header file being compiled into the executable file?

From Dev

C++ program can not be compiled

From Dev

Intellij exclude file from being compiled

From Dev

@import in less file being compiled twice

From Dev

Which class is suitable to play music file?

From Dev

Primary Constructor is not being compiled in C# 6.0

From Dev

program wont work after being compiled with py2exe

From Dev

How to detect if program is being compiled by cx_freeze?

From Dev

Can you access other program's memory using program compiled with mingw?

From Dev

Using a configuration file with a compiled Go program

From Dev

Play sound in Win32 program using MinGW + Eclipse

From Dev

Play sound in Win32 program using MinGW + Eclipse

From Dev

mingw: function not found when compiled with -std=c++11

From Java

How can I isolate the compiled logic of a C++ program from the rest of the file header data?

From Dev

How can a run a compiled java or c program from a shell file from outside its directory?

From Dev

NetBeans + MinGW + C - file not found

From Dev

Taylor Series Calculating Program in C compiled with GCC

From Dev

Finding dependencies for a compiled C++ program

From Dev

Re-write segment of a compiled C program

Related Related

  1. 1

    Include mingw libraries in compiled file

  2. 2

    Distribute a program compiled with MinGW g++

  3. 3

    Segmentation fault trying to execute a MinGW compiled C++ winapi test program

  4. 4

    if 0 is compiled in c program

  5. 5

    Play invisible music with batch file?

  6. 6

    play music in sdcard if exist file

  7. 7

    Play music file using Batch?

  8. 8

    Compiled c++ output file displays random character at end of program?

  9. 9

    C program compiled in cygwin with make: "cannot execute binary file"

  10. 10

    Program being compiled differently in 3 major C++ compilers. Which one is right?

  11. 11

    How is a header file being compiled into the executable file?

  12. 12

    C++ program can not be compiled

  13. 13

    Intellij exclude file from being compiled

  14. 14

    @import in less file being compiled twice

  15. 15

    Which class is suitable to play music file?

  16. 16

    Primary Constructor is not being compiled in C# 6.0

  17. 17

    program wont work after being compiled with py2exe

  18. 18

    How to detect if program is being compiled by cx_freeze?

  19. 19

    Can you access other program's memory using program compiled with mingw?

  20. 20

    Using a configuration file with a compiled Go program

  21. 21

    Play sound in Win32 program using MinGW + Eclipse

  22. 22

    Play sound in Win32 program using MinGW + Eclipse

  23. 23

    mingw: function not found when compiled with -std=c++11

  24. 24

    How can I isolate the compiled logic of a C++ program from the rest of the file header data?

  25. 25

    How can a run a compiled java or c program from a shell file from outside its directory?

  26. 26

    NetBeans + MinGW + C - file not found

  27. 27

    Taylor Series Calculating Program in C compiled with GCC

  28. 28

    Finding dependencies for a compiled C++ program

  29. 29

    Re-write segment of a compiled C program

HotTag

Archive