CMakeLists.txt target_link_library中的AWS SDK C++错误

syqv5f0l  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(57)

我一直在窗口中关注text,并试图为文档中显示的下一步做hello_s3项目。但是当我尝试cmake时,我一直得到这个错误:[CMake错误在/CMakeLists.txt:37(target_link_libraries)] [导入的库只能与target_link_libraries的接口关键字一起使用]

# Set the minimum required version of CMake for this project.
cmake_minimum_required(VERSION 3.13)

# Set the AWS service components used by this project.
set(SERVICE_COMPONENTS s3)

# Set this project's name.
project("test")

# Set the C++ standard to use to build this target.
# At least C++ 11 is required for the AWS SDK for C++.
set(CMAKE_CXX_STANDARD 11)

# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

if (WINDOWS_BUILD) # Set the location where CMake can find the installed libraries for the AWS SDK.
    string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
    list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif ()

# Find the AWS SDK for C++ package.
find_package(AWSSDK REQUIRED COMPONENTS s3)

if (WINDOWS_BUILD)
    # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

    # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
    # and set the proper subdirectory to the executables' location.

    AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR})
endif ()

add_executable(${test}
        hello_s3.cpp)

target_link_libraries(${test}
        ${AWSSDK_LINK_LIBRARIES})

字符串
我应该在哪里修理?
我试着把最后一行改成

target_link_libraries(${test}
        PRIVATE AWSSDK::aws-cpp-sdk-core
        PRIVATE AWSSDK::aws-cpp-sdk-s3)


但仍然不起作用,我使用VS 2022

wwtsj6pe

wwtsj6pe1#

你应该只使用一次。

target_link_libraries(${test}
    PRIVATE 
    AWSSDK::aws-cpp-sdk-core
    AWSSDK::aws-cpp-sdk-s3)

字符串

相关问题