Ncurses & curses - undefined link compiler

Good, so I initially tried to use some headers, which supposedly were only for windows, but this is bad, but I went and only reproduced what I needed using curses.h. However, I still get the same error.

"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/josh/Projects/Testing grounds/kbhit'
"/usr/bin/gmake"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/kbhit
gmake[2]: Entering directory `/home/josh/Projects/Testing grounds/kbhit'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -o dist/Debug/GNU-Linux-x86/kbhit build/Debug/GNU-Linux-x86/main.o  
build/Debug/GNU-Linux-x86/main.o: In function `kbhit()':


/home/josh/Projects/Testing grounds/kbhit/main.cpp:20: undefined reference to `stdscr'
/home/josh/Projects/Testing grounds/kbhit/main.cpp:20: undefined reference to `wgetch'
/home/josh/Projects/Testing grounds/kbhit/main.cpp:23: undefined reference to `ungetch'
collect2: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Linux-x86/kbhit] Error 1
gmake[2]: Leaving directory `/home/josh/Projects/Testing grounds/kbhit'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/josh/Projects/Testing grounds/kbhit'
gmake: *** [.build-impl] Error 2

So, I'm not 100% sure that the code should work as I expect. I'm just trying to compile this to test it. According to curses.h documentation, getch should return an ERR value if no keys are queued. I really don’t know what else is required here, I thought that all I have to do is include the heading in which the definitions were. This does not seem to be enough, but something must be missed. Here is a short test I'm trying to compile

#include <cstdlib>
#include <iostream>
#include <curses.h>
#include <ncurses.h>

using namespace std;

bool kbhit()
{
  int ch = getch();
  if(ch != ERR)
  {
    ungetch(ch);
    return true;
  }
  return false;

}

int main() {

  while(!kbhit())
  {
    cout << "no input";
  }
  cout << "Mummy, it over.";
  return 0;
}
+3
4

curses. -lncurses , .

+5

, -lx ( x - ) .

+1

You also need to link to the library, not just compile it with a header. Add -lncursesto the communication team. (See Also man ncurses.)

0
source

Example:

g++ -o myprogram myprogram.cpp -lncurses
0
source

All Articles