ncurses& curses-编译器未定义的引用 [英] ncurses & curses - compiler undefined references

查看:96
本文介绍了ncurses& curses-编译器未定义的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我最初一直试图使用一些仅用于Windows的标头,这很糟糕,但是我走了,只是使用curses.h复制了我需要的标头。但是我仍然收到完全相同的错误。

Okay so I had originally been attempting to use some headers that were supposedly for windows only, my bad, but I've gone and just reproduced what I need using curses.h. However I am still receiving the exact same kind of 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

因此,我不是100%确信代码甚至可以按我期望的那样工作。我只是试图编译它来测试它。根据curses.h文档,如果没有任何键排队,则getch应该返回值ERR。我真的不知道这里还需要什么,我想我需要做的就是包括定义所在的标头。但是,这似乎还不够,我必须错过一些东西。这是我要编译的简短测试

So, I am not 100% sure that the code should even work as I expect it to. I am just trying to compile this to test it. According to the curses.h documentation getch is supposed to return the value ERR if no keys are queued. I don't really know what else is required here, I thought all I needed to do was include the header the definitions were in. It seems like that isn't enough though, there must be something I have missed. Here is the short test I am 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's over.";
  return 0;
}


推荐答案

您没有针对curses库。您需要在链接您的makefile中的可执行文件的行中提供 -inccurses

You're not linking against the curses library. You need to provide -lncurses to the line that links your executable in your makefile.

这篇关于ncurses&amp; curses-编译器未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆