要在CMake中鏈接curses.h,在CMakeLists.txt文件中進行以下步驟:
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
target_link_libraries(your_target_name ${CURSES_LIBRARIES})
注意:將"your_target_name"替換為你的目標名稱。
完整的CMakeLists.txt示例:
cmake_minimum_required(VERSION 3.0)
project(YourProjectName)
# 查找ncurses庫
find_package(Curses REQUIRED)
# 添加可執行文件
add_executable(your_target_name your_source_files.cpp)
# 包含ncurses頭文件和鏈接ncurses庫
include_directories(${CURSES_INCLUDE_DIR})
target_link_libraries(your_target_name ${CURSES_LIBRARIES})
這樣,當你在CMake中構建你的項目時,它將鏈接并使用ncurses庫。