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

syqv5f0l  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(266)

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

  1. # Set the minimum required version of CMake for this project.
  2. cmake_minimum_required(VERSION 3.13)
  3. # Set the AWS service components used by this project.
  4. set(SERVICE_COMPONENTS s3)
  5. # Set this project's name.
  6. project("test")
  7. # Set the C++ standard to use to build this target.
  8. # At least C++ 11 is required for the AWS SDK for C++.
  9. set(CMAKE_CXX_STANDARD 11)
  10. # Use the MSVC variable to determine if this is a Windows build.
  11. set(WINDOWS_BUILD ${MSVC})
  12. if (WINDOWS_BUILD) # Set the location where CMake can find the installed libraries for the AWS SDK.
  13. string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
  14. list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
  15. endif ()
  16. # Find the AWS SDK for C++ package.
  17. find_package(AWSSDK REQUIRED COMPONENTS s3)
  18. if (WINDOWS_BUILD)
  19. # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
  20. # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this
  21. # and set the proper subdirectory to the executables' location.
  22. AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR})
  23. endif ()
  24. add_executable(${test}
  25. hello_s3.cpp)
  26. target_link_libraries(${test}
  27. ${AWSSDK_LINK_LIBRARIES})

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

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


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

wwtsj6pe

wwtsj6pe1#

你应该只使用一次。

  1. target_link_libraries(${test}
  2. PRIVATE
  3. AWSSDK::aws-cpp-sdk-core
  4. AWSSDK::aws-cpp-sdk-s3)

字符串

相关问题