Cmake does not support ncurses

I am a complete noob regarding cmake. My CMakeLists are really basic:

cmake_minimum_required(VERSION 2.4.6) #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) #For the Curses library to load: SET(CURSES_USE_NCURSES TRUE) include_directories( "src/" ) add_subdirectory(src) 

when I do the linker, I do not find the ncurses commands and in verbose make mode, I see that the compiler has not added -lncurses. What do I need to add to CMakeLists to make it work?

+9
source share
2 answers

Before using any third-party libraries, you must find it! in the case of ncurses you need to add find_package(Curses REQUIRED) and then use ${CURSES_LIBRARIES} in the call to target_link_libraries() and target_include_directories(... ${CURSES_INCLUDE_DIR}) .

+10
source

For a super noob, remember that target_link_libraries() must be lower than add_executable() :

 cmake_minimum_required(VERSION 2.8) project(main) find_package(Curses REQUIRED) include_directories(${CURSES_INCLUDE_DIR}) add_executable(main main.cpp) target_link_libraries(main ${CURSES_LIBRARIES}) 
+25
source

Source: https://habr.com/ru/post/1206025/


All Articles