ncurses beep don't work

Jan 20, 2016 at 1:15am
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 ;
}


Jan 20, 2016 at 3:32am
Do you have a speaker connected to the motherboard?
Jan 20, 2016 at 8:57am
You might have to run your program as root.
Jan 20, 2016 at 9:59pm
@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
Jan 20, 2016 at 10:02pm
If you use ncurses you must link the library by passing -lncurses to g++.
Last edited on Jan 20, 2016 at 10:07pm
Jan 20, 2016 at 10:10pm
@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
Jan 20, 2016 at 10:12pm
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 Jan 20, 2016 at 10:16pm
Jan 20, 2016 at 10:32pm
@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.
Jan 20, 2016 at 10:34pm
@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?
Jan 20, 2016 at 10:36pm
@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.