lncurses on Clion with Ubuntu

lncurses on Clion with Ubuntu

本文关键字:Ubuntu with Clion on lncurses      更新时间:2023-10-16

我正在用C为学校做一个项目,我正在使用Clion作为idee。我已经使用命令在 Ubuntu 中安装了 ln curses

sudo apt-get install libncurses<ver>-dev

使用应,程序有效!但是我想用 idee 做一些调试。我的cmake文件是这个

cmake_minimum_required(VERSION 3.12)
project(progetto_pipe_2 C)
set(CMAKE_C_STANDARD 99)
add_executable(progetto_pipe_2 main.c movimento.c movimento.h grafica.c grafica.h area_gioco.c area_gioco.h)

如果我从 idee 启动应用程序,则会出现以下错误:

undefined reference to `initscr' ecc ecc

您需要在 cmake 配置文件中链接库。查看这篇文章: 如何在 Cmake 中链接 curses.h?

尝试:

cmake_minimum_required(VERSION 3.12) 
project(progetto_pipe_2 C)
set(CMAKE_C_STANDARD 99)
# Define the target
add_executable(progetto_pipe_2 main.c movimento.c movimento.h grafica.c grafica.h area_gioco.c area_gioco.h)
# Look for the package you want to link
find_package( Curses REQUIRED )
# Include the directories of the package (to find curses.h for instance)
target_include_directories(progetto_pipe_2 PRIVATE ${CURSES_INCLUDE_DIRS} )
# Link the library
target_link_libraries(progetto_pipe_2 PRIVATE ${CURSES_LIBRARIES} )