假设我使用了 find_package(SDL REQUIRED),现在我需要通过 target_link_libraries 链接到该库,要传递给 target_link_libraries 的变量名称是什么?一般来说,除了启发式猜测之外,还有其他方法可以找到这些变量吗?我尝试过 SDL_LIBRARY、SDL2_LIBRARY 和 SDL_LIBRARIES。我确实安装了 sdl2。
我本以为这会起作用,但它没有:
cmake_minimum_required(VERSION 3.10)
project(someProject)
# Find SDL2
find_package(SDL REQUIRED)
find_package(SDL_image REQUIRED)
# Include directories
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
# Set source files
set(SOURCES main.cpp)
# Set executable
add_executable(someProject ${SOURCES})
# Link libraries
target_link_libraries(someProject ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
> CMake Error at
> /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230
> (message): Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR)
> Call Stack (most recent call first):
> /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600
> (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake/Modules/FindSDL.cmake:224
> (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:5 (find_package)
>
>
> -- Configuring incomplete, errors occurred!