ncurses & curses - 编译器未定义引用
ncurses & curses - compiler undefined references
好的,所以我最初一直在尝试使用一些据说仅适用于 Windows 的标头,我的错,但我已经走了,只是使用 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;
}
你没有链接到诅咒库。您需要向在生成文件中链接可执行文件的行提供-lncurses
。
示例:
g++ -o myprogram myprogram.cpp -lncurses
另请注意,-lx 参数(其中 x 是你的库)应始终跟在源文件和目标文件之后。
您还需要针对库进行链接,而不仅仅是针对标头进行编译。 将-lncurses
添加到链接命令。 (另请参阅man ncurses
。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用