Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake does non link ncurses

Tags:

cmake

ncurses

I am a total noob concerning cmake. My CMakeLists is 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 make the linker does not find the ncurses commands and in the verbose mode of make I see that the compiler did not add the -lncurses. What do I have to add to the CMakeLists to make it work?

like image 495
G-Mos Avatar asked Nov 01 '14 21:11

G-Mos


People also ask

How do I link my ncurses library?

To use ncurses library functions, you have to include ncurses. h in your programs. To link the program with ncurses the flag -lncurses should be added.


2 Answers

For the super noob, remember target_link_libraries() needs to be below 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})
like image 171
wafflecat Avatar answered Sep 21 '22 06:09

wafflecat


before use some third party libs, you ought to find it! in case of ncurses you need to add find_package(Curses REQUIRED) and then use ${CURSES_LIBRARIES} in a call to target_link_libraries() and target_include_directories(... ${CURSES_INCLUDE_DIR}).

like image 30
zaufi Avatar answered Sep 22 '22 06:09

zaufi