can't compile library ncurses on Ubuntu

Answered

I'm doing a project for school with C, i'm using Clion as idee. I already installed the ln curses in Ubuntu with the command:

sudo apt-get install libncurses-dev libncursesw5-dev

Using the shell, the program works! But I would like to do some debugging with idee.

This is that appear when i try to compile the code:

/snap/clion/175/bin/cmake/linux/bin/cmake --build "/home/matteo/CLionProjects/codici lezione/slide 7/game/cmake-build-debug" --target game
[1/1] Linking C executable game
FAILED: game
: && /bin/cc -g CMakeFiles/game.dir/main.c.o -o game -lmain.c && :
/usr/bin/ld: cannot find -lmain.c
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

and this is the CMakeLists.txt :

cmake_minimum_required(VERSION 3.21)
project(game C)

set(CMAKE_C_STANDARD 90)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})

add_executable(game main.c)
target_link_libraries(game main.c ${CURSES_INCLUDE_DIR})

System:
Linux Ubuntu 20.04.3 LTS - 64-bit
GNOME version 3.36.8
CMake Version 3.21

2 comments
Comment actions Permalink

Hello!

target_link_libraries(game main.c ${CURSES_INCLUDE_DIR})

That's incorrect. You need to link libraries, not files or directories. Please read our quick CMake tutorial (https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#link-libs) or the CMake documentation.

1
Comment actions Permalink

Thank you so much!! I solved with:

target_link_libraries(${PROJECT_NAME} -lncursesw)
0

Please sign in to leave a comment.