我想让我的CLion与C的curses库兼容。这是我的示例应用程序
#include <stdio.h>
#include "ncurses.h"
int main() {
initscr();
printw("Hello world");
refresh();
getch();
endwin();
return 0;
}
这是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(untitled C)
set(CMAKE_C_STANDARD 99)
add_executable(untitled main.c)
target_link_libraries(${PROJECT_NAME} ncurses)
但是当我运行应用程序时,我遇到了此错误
Error opening terminal: unknown.
您需要编辑CMakeLists.txt文件,如下所示:
cmake_minimum_required(VERSION 3.17)
project(untitled C)
set(CMAKE_CXX_STANDARD 14)
add_compile_options(-g -Wall -Wextra -pedantic)
set(INCLUDE_DIR include)
include_directories (${INCLUDE_DIR})
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_executable(untitled main.cpp)
target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES})
现在刚刚测试过,它在 Clion 最新版本中运行良好(我在撰写本文时这个答案是 v2020.3(
请注意,无法调试 lib 命令,但您可以在控制台终端中编译和运行(即不要从 CLion 内部的"终端"运行它,而是使用系统终端(,这是因为代码设计为在文本类型终端中运行,而 CLion 内部的终端是图形终端。
我希望这有帮助
祝你好运
H