ncurses beep don't work

I'm using Ubuntu Linux and trying to yield a beep sound in several ways. But nothing is working:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <ncurses.h>

int main()
{  
  std::cout << '\a' << '\7' << std::endl ;

  beep() ;

  return 0 ;
}


Do you have a speaker connected to the motherboard?
You might have to run your program as root.
@helios
Do you have a speaker connected to the motherboard?

Yes, I'm on my notebook.

@Peter87
You might have to run your program as root.

I can't run it because it isn't compiling yet.

1
2
3
4
~/bin/cpp/test$ g++ -Wall -std=c++14 -o test test.cpp
/tmp/cctC4yjf.o: In function `main':
test.cpp:(.text+0x2e): undefined reference to `beep'
collect2: error: ld returned 1 exit status
If you use ncurses you must link the library by passing -lncurses to g++.
Last edited on
@Peter87
You need to pass -lncurses to g++.

Yes, I had read about that, but it didn't work for me.

1
2
3
4
~/bin/cpp/test$ sudo g++ -Wall -std=c++14 -lncurses -o test test.cpp
/tmp/cc6fxOvj.o: In function `main':
test.cpp:(.text+0x2e): undefined reference to `beep'
collect2: error: ld returned 1 exit status
In the future, instead of saying "doesn't work", state a more precise nature of the problem. For example, "it doesn't compile", "it crashes", "it hangs", "it runs, but the output is wrong", etc.

Yes, I'm on my notebook.
Notebooks don't always have PC speakers. PC speakers are little buzzers that connect directly to the motherboard and don't use a sound card.
http://ep.yimg.com/ay/yhst-27518546784426/internal-speaker-24.jpg

EDIT: Try surrounding the #include with extern "C" { }
Last edited on
@helios
In the future, instead of saying "doesn't work", state a more precise nature of the problem.

I'm sorry. I don't speak english, therefore it isn't easy to explain for me. Also, I'm a beginner, not always I know what is going on. I pasted the compiler command and message, I thougth that it was suficient. In a previous post I talked that it did not was compiling as well.
@helios
Notebooks don't always have PC speakers. PC speakers are little buzzers that connect directly to the motherboard and don't use a sound card.

I didn't know that. Without speakers isn't possible to yield a beep sound?
@helios
EDIT: Try surrounding the #include with extern "C" { }

Are you talking about this?
#include "ncurses.h"
I tried that, but it didn't compile yet.
Topic archived. No new replies allowed.