Thread: Linking / PlaySound problem

  1. #1
    Registered User
    Join Date
    Dec 2010

    Linking / PlaySound problem

    I'm having a bit of trouble with PlaySound. I've attempted to link winmm.lib and libwinmm.a with no success and an error saying: ld.exe||cannot find -lwinmm.lib|. I'm using Code::Blocks 10.5 and Windows, donno if that will help but hey. Anywhos, on to the code:

    #include <iostream>
    #include <windows.h>
    #include <Mmsystem.h>
    #pragma comment(lib,"winmm.lib")
    using namespace std;
    int main()
        PlaySound("music.wav", NULL, SND_FILENAME|SND_LOOP);
        return 0;
    Thanks in advance for any help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    You'll probably have to provide the complete path to the library, since that library is not in MinGW's default library path.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > #pragma comment(lib,"winmm.lib")
    I'm pretty sure this only works if you're using a microsoft compiler and linker.
    For every other sane approach, you add your dependencies in your project / makefile.

    #pragma comment
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Ok, it works, thanks!
    But, one problem I'm working on a program thats kinda like Guitar Hero, so the timing of the music needs to be perfect, but when it plays a song there is a delay from when its told to play the song to when the song starts playing. Is there any way to load a song before playing it, or something so the song will instantly start playing when told to?
    Last edited by frank42; 12-12-2010 at 03:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Playsound problem
    By rEtard in forum Windows Programming
    Replies: 13
    Last Post: 02-07-2006, 08:38 AM
  3. Linking problem
    By Agent89 in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2005, 03:03 PM
  4. Long file linking problem
    By hypertension in forum C Programming
    Replies: 3
    Last Post: 10-15-2002, 09:55 PM
  5. Linking problem...
    By BrianK in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2002, 04:13 PM