13

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?

ShahinSorkh
  • 471
  • 1
  • 9
  • 19
G-Mos
  • 143
  • 1
  • 2
  • 6
  • 1
    You should not set EXECUTABLE_OUTPUT_PATH relative to PROJECT_SOURCE_DIR as this makes it impossible to perform proper out-of-tree builds. – datenwolf Nov 01 '14 at 21:59

2 Answers2

35

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})
LogicStuff
  • 19,057
  • 6
  • 51
  • 72
wafflecat
  • 984
  • 9
  • 15
  • I was using `Curses_INCLUDE_DIR` and `Curses_LIBRARIES` once I uppercased them, it worked – phoxd Jan 06 '20 at 20:35
12

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}).

zaufi
  • 6,284
  • 25
  • 33
  • 4
    Thank you! This worked! For complete noobs it is target_link_libraries(your_exe ${CURSES_LIBRARIES}) – G-Mos Nov 06 '14 at 12:33