Find the answer to your Linux question:
Results 1 to 8 of 8

Thread: beep problem

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Banned jan1024188's Avatar
    Join Date
    Jul 2006
    Location
    EU, SLOVENIA
    Posts
    1,549

    beep problem


    http://www.daniweb.com/techtalkforums/thread57693.html

    i have

    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    int main()
    {
      puts("using winAPI Beep(frequency_hrz, duration_ms)...");
      Beep(523,500);  /* 523 hertz  for 500 milliseconds*/
      Beep(587,500);
      Beep(659,500);
      Beep(698,500);
      Beep(784,500);
      usleep(500);    
      puts("\n\\a makes a beep on the internal speaker too ...");
      usleep(500);
      puts("\a");
      usleep(500);
      puts("\a");
      
      getchar(); 
      return 0;
    }
    Beep is for windows only
    so i get this err
    Code:
    gjan@jan-desktop:~$ gcc beep.c
    /tmp/cc2Nmnm7.o: In function `main':beep.c:(.text+0x38): undefined reference to `Beep'
    :beep.c:(.text+0x4c): undefined reference to `Beep'
    :beep.c:(.text+0x60): undefined reference to `Beep'
    :beep.c:(.text+0x74): undefined reference to `Beep'
    :beep.c:(.text+0x88): undefined reference to `Beep'
    collect2: ld returned 1 exit status
    jan@jan-desktop:~$
    what to do?

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    4,087
    Why dont you add:

    Code:
    #if !(WIN32)
    #define Beep(x,y)
    #endif
    after the #defines and before the main(...).

    You could even change it to a function that takes the parameters, figures out what file to play, and dumps that file out to the multimedia system under Linux.

    There is a 'beep' call in the <curses.h> library, but I dont think it's quite so flexible.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Banned jan1024188's Avatar
    Join Date
    Jul 2006
    Location
    EU, SLOVENIA
    Posts
    1,549
    i've tryed adding
    <curses.h>
    but that doesnt help so i've added

    #if !(WIN32)
    #define beep(x,y)
    #endif
    but there in NO beep

    what to do?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    Curses' beep uses no parameters, and that macro definition you interested will just tell the preprocessor to replace all 'calls' to Beep with nothing.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  6. #5
    Banned jan1024188's Avatar
    Join Date
    Jul 2006
    Location
    EU, SLOVENIA
    Posts
    1,549
    so what should i do?

  7. #6
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Something like this, perhaps?
    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    #if !(WIN32)
    #define Beep(x,y) ( putchar('\a') )
    #endif
    
    int main()
    {
      puts("using winAPI Beep(frequency_hrz, duration_ms)...");
      Beep(523,500);  /* 523 hertz  for 500 milliseconds*/
      Beep(587,500);
      Beep(659,500);
      Beep(698,500);
      Beep(784,500);
      usleep(500);    
      puts("\n\\a makes a beep on the internal speaker too ...");
      usleep(500);
      puts("\a");
      usleep(500);
      puts("\a");
      
      getchar(); 
      return 0;
    }
    If you're on a Windows system, the Beep() function will be called. If you're not, it will call the macro, which just prints the alarm character.

  8. #7
    Banned jan1024188's Avatar
    Join Date
    Jul 2006
    Location
    EU, SLOVENIA
    Posts
    1,549
    nope...that doesnt work.....i dont have windows

  9. #8
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    -->
    I think the point of Cabhan's solution was to provide an alternative for non-Windows environments.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •