cmake做非链接ncurses

G-M*_*Mos 9 ncurses cmake

我是一个关于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)
Run Code Online (Sandbox Code Playgroud)

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

waf*_*cat 26

对于超级菜鸟,记住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})
Run Code Online (Sandbox Code Playgroud)


zau*_*ufi 10

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

  • 谢谢!这有效!对于完整的新手,它是target_link_libraries(your_exe $ {CURSES_LIBRARIES}) (4认同)