Ncurses包含在Cygwin中,但是getch()不起作用。说这是一个未声明的标识符

问题描述 投票:0回答:1

我正在使用Cygwin,并试图编写一个游戏培训师。我希望能够使用户只需按一个键即可启用/禁用功能,而后不必再按Enter。看起来ncurses库中的getch()应该能够做到这一点。但是,当我尝试使用getch()时,出现错误“使用未定义的标识符'getch'”。然后,构建输出还会显示对ncwrap_stdscr和wgetch的未定义引用。

我曾尝试包括curses.h而不是ncurses,但这给出了相同的错误(这很有意义,因为ncurses头文件似乎只是与curses.h的符号链接。

理论上,我认为这段代码应该构建得很好:

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

int main() {
    int in = getch();
    std::cout << in << std::endl;
}

这是构建的输出:

CMakeFiles/getchTest.dir/main.cpp.o: In function `main':
/cygdrive/c/Users/Sasschary/CLionProjects/getchTest/main.cpp:5: undefined reference to `ncwrap_stdscr'
/cygdrive/c/Users/Sasschary/CLionProjects/getchTest/main.cpp:5: undefined reference to `wgetch'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/getchTest.dir/build.make:84: getchTest.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/getchTest.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/getchTest.dir/rule] Error 2
make: *** [Makefile:118: getchTest] Error 2

感谢您的帮助!

c++ ncurses
1个回答
0
投票

我需要在ncurses库中具有cmake链接。解决方法是添加

target_link_libraries(BasicTrainer ncurses)

到我的cmake文件。谢谢大家的帮助!

© www.soinside.com 2019 - 2024. All rights reserved.