"/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 -Iusr/include/ -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 -L/usr/include/ncurses -L/usr/include/ncurses6 -L/usr/include/ncursesw -lncurses.h
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld: cannot find -lncurses.h
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
BUILD FAILED (exit value 2, total time: 477ms)
它似乎找不到“lcurses”,但我从未定义它寻找 lcurses。我实际上添加了要链接的 ncurse 库。
我已经导航到/usr/include/ncurses,实际上那里应该有文件。
我不完全了解整个编译过程中发生了什么,这有点超出我的理解范围。我只知道有人告诉我链接我需要的库。 ncurses.h 在那里,这就是我的代码。
#include <iostream>
#include <ncurses/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;
}
任何帮助都将受到欢迎;我迷路了。
最佳答案
这不是您的 C++ 代码的问题,而是您的构建环境的问题,您使用的是 netbeans IDE 吗?
据我所知,这段代码根本不需要 ncruses,而 NetBeans 的链接指令呢?已为您设置指向一个 ncruses.h 文件,其中它应该是这样的“-Wl,-lncurses”或仅“-lncurses”。所以猜测是在 netbeans 的某个地方你应该指出你写的库名称 ncruses.h 而不是只有 ncruses(我想,不确定)
尝试询问 pkg-config ncurses 的哪些参数应该在您的机器上“pkg-config --libs ncurses”和“pkg-config --cflags ncurses”
关于c++ - kbhit 测试编译失败 'cannot find -lcurses',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10571461/