cmake做非链接ncurses

时间:2014-11-01 21:21:17

标签: cmake ncurses

我是关于cmake的总菜鸟。我的CMakeLists非常基础:

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)

当我使链接器找不到ncurses命令时,在make的详细模式下,我看到编译器没有添加-lncurses。我需要添加什么才能使CMakeLists工作?

2 个答案:

答案 0 :(得分:25)

对于超级菜鸟,请记住target_link_libraries()需要低于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})

答案 1 :(得分:9)

在使用某些第三方库之前,你应该找到它! 如果是ncurses,您需要添加find_package(Curses REQUIRED),然后在调用${CURSES_LIBRARIES}target_link_libraries()时使用include_directories(${CURSES_INCLUDE_DIR})