0

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<ver>-dev

Using the shall, the program works! But I would like to do some debugging with idee. My cmake file is this

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)

If I start the application from idee , the following error appears is:

undefined reference to `initscr' ecc ecc
Stoogy
  • 1,307
  • 3
  • 16
  • 34
Luca Ladu
  • 3
  • 2
  • Possible duplicate of [How to link curses.h in Cmake?](https://stackoverflow.com/questions/35159634/how-to-link-curses-h-in-cmake) – mohabouje Jan 23 '19 at 10:08
  • Please proofread your writing; it's hard to understand. There's no letter el or space in `ncurses` and an IDE is an acronym for "Integrated Development Environment"; it only has one e and should be in all caps. We can figure out what you mean, but it's easier if you write in a more standard way so we don't need to figure out whether "idee" is "IDE" or "idea" or something. – Daniel H Jan 23 '19 at 10:22
  • sorry I was wrong writing IDE – Luca Ladu Jan 23 '19 at 10:27

1 Answers1

0

You need to link the library in your cmake configuration file. Check this post: How to link curses.h in Cmake?

Try:

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} )
mohabouje
  • 3,867
  • 2
  • 14
  • 28
  • /opt/clion-2018.2.6/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" "/home/luca/CLionProjects/backup progetto pipe/progetto_pipe_2" -- Found Curses: /usr/lib/x86_64-linux-gnu/libcurses.so CMake Error at CMakeLists.txt:8 (target_link_libraries): Cannot specify link libraries for target "progetto_pipe_2" which is not built by this project. -- Configuring incomplete, errors occurred! See also "/home/luca/CLionProjects/backup progetto pipe/progetto_pipe_2/cmake-build-debug/CMakeFiles/CMakeOutput.log". [Finished] – Luca Ladu Jan 23 '19 at 10:16
  • You should link a library after declaring the target. See the modifications. – mohabouje Jan 23 '19 at 10:27
  • Thanks, but now comes the following error if I try to use debugging ____ Error opening terminal: unknown. Process finished with exit code 1 – Luca Ladu Jan 23 '19 at 10:33
  • After these commands initscr(); noecho(); curs_set(0) – Luca Ladu Jan 23 '19 at 10:37
  • You should open another question for that. That error is not related to library linkage or the cmake configuration. – mohabouje Jan 23 '19 at 10:41