CMake 不链接 ncurses

问题描述 投票:0回答:2

我完全是 CMake 菜鸟。我的

CMakeLists.txt
真的很基础:

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)

当我 make 时,链接器没有找到 ncurses 命令,在 make 的详细模式下,我看到编译器没有添加

-lncurses
。我必须向 CMakeLists 添加什么才能使其正常工作?

cmake ncurses
2个回答
35
投票

对于超级菜鸟,记住

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

12
投票

在使用一些第三方库之前,你应该找到它! 在

ncurses
的情况下,您需要添加
find_package(Curses REQUIRED)
,然后在调用
${CURSES_LIBRARIES}
target_link_libraries()
时使用
target_include_directories(... ${CURSES_INCLUDE_DIR})

© www.soinside.com 2019 - 2024. All rights reserved.