CMake不链接ncurses

qq24tv8q  于 2023-04-06  发布在  其他
关注(0)|答案(2)|浏览(192)

我对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添加什么才能使其工作?

zwghvu4y

zwghvu4y1#

对于超级菜鸟,记住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})
20jt8wwn

20jt8wwn2#

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

相关问题