2014-11-01 22 views
5

Sono un noob totale riguardante cmake. I miei CMakeLists è davvero fondamentale:cmake non collega ncurses

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) 

quando faccio il linker non trova i comandi ncurses e in modalità verbose del make vedo che il compilatore non aggiungere i -lncurses. Cosa devo aggiungere alle CMakeLists per farlo funzionare?

+1

Non impostare EXECUTABLE_OUTPUT_PATH rispetto al PROJECT_SOURCE_DIR in quanto ciò rende impossibile eseguire una corretta out-of-albero costruisce. – datenwolf

risposta

7

prima di utilizzare alcune librerie di terze parti, dovresti trovarlo! in caso di ncurses è necessario aggiungere find_package(Curses REQUIRED) e quindi utilizzare ${CURSES_LIBRARIES} in una chiamata a target_link_libraries() e include_directories(${CURSES_INCLUDE_DIR}).

+2

Grazie! Questo ha funzionato! Per i noob completi è target_link_libraries (your_exe $ {CURSES_LIBRARIES}) –

16

per il super niubbo, ricordate target_link_libraries() ha bisogno di essere seguito 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})