Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: MinGW gcc Compile of C code on Windows  (Read 12610 times)

0 Members and 1 Guest are viewing this topic.

thed

  • Newbie
  • *
  • Posts: 2
    • View Profile
MinGW gcc Compile of C code on Windows
« on: August 12, 2008, 01:14:22 pm »
Hello all. I have a simple source file (see below) to play an ogg file. Compiling with MinGW/MSYS on Windows XP using

gcc filename.c -o filename.exe -lcsfml-audio

or

gcc filename.c -o filename.exe -lcsfml-audio-d

appears to create the executable, however, when the executable is activated, a (command-prompt) window appears for an instant and then quickly disappears, with no sound being played and no error messages being displayed. The ogg file is located in the same location as the executable. When the ogg file referred to in the script is absent, I receive a "Failed to open 'absentfile.ogg' for reading" error message before the program shuts down. The SFML code i'm using is:

#include <SFML/Audio.h>

main()
 {
 
    sfMusic* Music;
             
     /* Load a music to play */
     Music = sfMusic_CreateFromFile("soundfile.ogg");
     
     /* Play the music */
     sfMusic_Play(Music);
 
     /* Cleanup resources */
     sfMusic_Destroy(Music);
       
 }

Any suggestions would be appreciated. Thanks.

SirJulio

  • Full Member
  • ***
  • Posts: 241
    • View Profile
MinGW gcc Compile of C code on Windows
« Reply #1 on: August 12, 2008, 02:36:19 pm »
Hi,

all music playing func in SFML are threaded, so to keep your app open when your sound is played, you need to add something like that :

Code: [Select]
while (sfMusic_GetStatus == sfPlaying)
    sfSleep(0.1f);

thed

  • Newbie
  • *
  • Posts: 2
    • View Profile
MinGW gcc Compile of C code on Windows
« Reply #2 on: August 12, 2008, 05:11:32 pm »
Thanks SirJulio.

I modified your suggested code to:

   while (sfPlaying)
     sfSleep(0.1f);

and it worked a treat. Many thanks.