c++ - ncurses & curses - 编译器 undefined reference

标签 c++ compiler-errors

好吧,所以我最初一直在尝试使用一些据称仅适用于 Windows 的 header ,我的错,但我已经走了,只是使用 curses.h 复制了我需要的东西。但是我仍然收到完全相同类型的错误。

"/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

因此,我不能 100% 确定代码是否会像我预期的那样工作。我只是想编译它来测试它。根据 curses.h 文档,如果没有键排队,getch 应该返回值 ERR。我真的不知道这里还需要什么,我认为我需要做的就是包含定义所在的标题。但这似乎还不够,一定有我遗漏的东西。这是我要编译的简短测试

#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's over.";
  return 0;
}

最佳答案

您没有链接到 curses 库。您需要将 -lncurses 提供给链接您的 makefile 中的可执行文件的行。

关于c++ - ncurses & curses - 编译器 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10267178/

相关文章:

c++ - ON_REGISTERED_MESSAGE Win32 等效项

c++ - move 语义在这里如何工作?

spring - 上下文初始化失败或加载属性

java - Java命令提示符编译错误

c++ - C++错误: expected ',' or ';' before '{' token when their is

c++ - 通过引用传递迭代器会产生错误 : cannot convert parameter 1 from 'const data' to 'data &

java - 为什么 Eclipse 没有自带编译器?

c++ - getline() 省略输出字符串的第一个字母

qt - 带有OpenCV库的编译错误Qt Creator(ubuntu)

c# - Crystal Report WinForm如何修复它错误对象引用未设置为对象的实例?