aws-sdk-cpp编译2

minio-cpp是一款文件系统服务的客户端,最近开发要用到,最开始从官网下载编译都是成功的,但是在使用示例的时候不通过,听说只在Linux上可以用,在Window上不能用,因此改用aws-sdk-cpp来实现客户端连接。用cmake编译aws-sdk-cpp时,编完后没有aws-cpp-sdk-transfer模块。本篇介绍使用vcpkg编译aws-sdk-cpp。

开发环境:window 11  Qt5.15.2, VS2022

首先参考官方的编译文档

GitHub - aws/aws-sdk-cpp: AWS SDK for C++

切换到F:\qtexample

git clone https://github.com/Microsoft/vcpkg.git

这步完成这后,切换到vcpkg目录

cd vcpkg

执行以下三条命令

./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install aws-sdk-cpp


Call Stack (most recent call first):
  ports/aws-crt-cpp/portfile.cmake:36 (vcpkg_copy_pdbs)
  scripts/ports.cmake:192 (include)


-- Installing: F:/qtexample/vcpkg/packages/aws-crt-cpp_x64-windows/share/aws-crt-cpp/copyright
-- Performing post-build validation
Stored binaries in 1 destinations in 321 ms.
Elapsed time to handle aws-crt-cpp:x64-windows: 27 s
aws-crt-cpp:x64-windows package ABI: 76fa04f59a00998fc5f03f8267146ecb437f8c6fc8a611c73f4b74f53fc26d97
Installing 15/16 zlib:x64-windows@1.3.1...
Elapsed time to handle zlib:x64-windows: 19.1 ms
zlib:x64-windows package ABI: 6f1d40f5c56cc1640c0700e444ca2e43b2dd2026b8b184057b6d448807b6f571
Installing 16/16 aws-sdk-cpp[core,dynamodb,kinesis,s3]:x64-windows@1.11.352...
Building aws-sdk-cpp[core,dynamodb,kinesis,s3]:x64-windows@1.11.352...
CMake Warning at scripts/cmake/vcpkg_buildpath_length_warning.cmake:4 (message):
  aws-sdk-cpp's buildsystem uses very long paths and may fail on your system.

  We recommend moving vcpkg to a short path such as 'C:\src\vcpkg' or using
  the subst command.
Call Stack (most recent call first):
  ports/aws-sdk-cpp/portfile.cmake:1 (vcpkg_buildpath_length_warning)
  scripts/ports.cmake:192 (include)


-- Downloading https://github.com/aws/aws-sdk-cpp/archive/1.11.352.tar.gz -> aws-aws-sdk-cpp-1.11.352.tar.gz...
-- Extracting source F:/qtexample/vcpkg/downloads/aws-aws-sdk-cpp-1.11.352.tar.gz

安装成功后在F:\qtexample\vcpkg\installed\x64-windows目录

这种安装成功后也有aws-cpp-sdk-transfer模块的dll和lib,因此得添加aws-cpp-sdk-transfer这个模块的安装

PS F:\qtexample\vcpkg> ./bootstrap-vcpkg.sh
PS F:\qtexample\vcpkg> ./vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=F:/qtexample/vcpkg/scripts/buildsystems/vcpkg.cmake"

All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.

单独安装aws-cpp-sdk-transfer模块

PS F:\qtexample\vcpkg> ./vcpkg install aws-sdk-cpp[transfer]
Computing installation plan...
The following packages will be rebuilt:
    aws-sdk-cpp[core,dynamodb,kinesis,s3,transfer]:x64-windows@1.11.352
warning: If you are sure you want to rebuild the above packages, run the command with the --recurse option.
PS F:\qtexample\vcpkg> ./vcpkg install --recurse aws-sdk-cpp[transfer]
Computing installation plan...
The following packages will be rebuilt:
    aws-sdk-cpp[core,dynamodb,kinesis,s3,transfer]:x64-windows@1.11.352
Detecting compiler hash for triplet x64-windows...
-- Automatically setting %HTTP(S)_PROXY% environment variables to "127.0.0.1:6987".
Compiler found: D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe
Restored 0 package(s) from C:\Users\cheny\AppData\Local\vcpkg\archives in 436 us. Use --debug to see more details.
Removing 1/2 aws-sdk-cpp:x64-windows
Elapsed time to handle aws-sdk-cpp:x64-windows: 288 ms
Installing 2/2 aws-sdk-cpp[core,dynamodb,kinesis,s3,transfer]:x64-windows@1.11.352...
Building aws-sdk-cpp[core,dynamodb,kinesis,s3,transfer]:x64-windows@1.11.352...
CMake Warning at scripts/cmake/vcpkg_buildpath_length_warning.cmake:4 (message):
  aws-sdk-cpp's buildsystem uses very long paths and may fail on your system.

  We recommend moving vcpkg to a short path such as 'C:\src\vcpkg' or using
  the subst command.
Call Stack (most recent call first):
  ports/aws-sdk-cpp/portfile.cmake:1 (vcpkg_buildpath_length_warning)
  scripts/ports.cmake:192 (include)


-- Using cached aws-aws-sdk-cpp-1.11.352.tar.gz.
-- Cleaning sources at F:/qtexample/vcpkg/buildtrees/aws-sdk-cpp/src/1.11.352-0db2abf4a9.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source F:/qtexample/vcpkg/downloads/aws-aws-sdk-cpp-1.11.352.tar.gz
-- Applying patch fix-aws-root.patch
-- Applying patch lock-curl-http-and-tls-settings.patch
-- Applying patch fix_find_curl.patch
-- Applying patch find-dependency.patch
-- Using source at F:/qtexample/vcpkg/buildtrees/aws-sdk-cpp/src/1.11.352-0db2abf4a9.clean
-- Found external ninja('1.11.0').
-- Configuring x64-windows-dbg
-- Configuring x64-windows-rel
-- Building x64-windows-dbg
-- Building x64-windows-rel
CMake Warning at scripts/cmake/vcpkg_copy_pdbs.cmake:44 (message):
  Could not find a matching pdb file for:

      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/bin/aws-cpp-sdk-core.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/bin/aws-cpp-sdk-dynamodb.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/bin/aws-cpp-sdk-kinesis.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/bin/aws-cpp-sdk-s3.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/bin/aws-cpp-sdk-transfer.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/debug/bin/aws-cpp-sdk-core.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/debug/bin/aws-cpp-sdk-dynamodb.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/debug/bin/aws-cpp-sdk-kinesis.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/debug/bin/aws-cpp-sdk-s3.dll
      F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/debug/bin/aws-cpp-sdk-transfer.dll

Call Stack (most recent call first):
  ports/aws-sdk-cpp/portfile.cmake:57 (vcpkg_copy_pdbs)
  scripts/ports.cmake:192 (include)


-- Installing: F:/qtexample/vcpkg/packages/aws-sdk-cpp_x64-windows/share/aws-sdk-cpp/copyright
-- Performing post-build validation
Stored binaries in 1 destinations in 1.2 s.
Elapsed time to handle aws-sdk-cpp:x64-windows: 2.4 min
aws-sdk-cpp:x64-windows package ABI: dedb36f98d779109cbde73e5809b70a454710cfc1dd1143b6260a76894955e4b
Total install time: 2.4 min
The package aws-sdk-cpp:x64-windows provides CMake targets:

    When using AWSSDK, AWSSDK_ROOT_DIR must be defined by the user.
    find_package(AWSSDK CONFIG COMPONENTS core dynamodb kinesis s3 REQUIRED)
    target_include_directories(main PRIVATE ${AWSSDK_INCLUDE_DIRS})
    target_link_libraries(main PRIVATE ${AWSSDK_LIBRARIES})

    OR

    find_package(aws-cpp-sdk-core REQUIRED)
    target_include_directories(main PRIVATE aws-cpp-sdk-core)
    target_link_libraries(main PRIVATE aws-cpp-sdk-core)

PS F:\qtexample\vcpkg>

最后安装完成后,transfer安装到对应的目录里

 代码测试

pro文件

QT       += core gui
 
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
INCLUDEPATH += ../include
 
CONFIG += c++17
 
DESTDIR = ../bin
 
LIBS += -L../bin -laws-cpp-sdk-core
LIBS += -L../bin -laws-cpp-sdk-s3
LIBS += -L../bin -laws-cpp-sdk-transfer
 
message($$OUT_PWD)
 
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
SOURCES += \
    main.cpp \
    mainwindow.cpp
 
HEADERS += \
    mainwindow.h \
 
FORMS += \
    mainwindow.ui
 
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

dll和lib文件都放在bin目录下。

cpp文件

//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
#include <QDebug>
#include <string.h>
 
#include <iostream>
#include <fstream>
 
#include "aws/s3/S3Client.h"
#include "aws/core/Aws.h"
#include "aws/core/auth/AWSCredentialsProvider.h"
#include "aws/s3/model/PutObjectRequest.h"
#include "aws/s3/model/GetObjectRequest.h"
 
 
using namespace std;
using namespace Aws::S3;
using namespace Aws::S3::Model;
 
//#pragma comment(lib, "ws2_32.lib")
 
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->btnTest, SIGNAL(clicked()), this, SLOT(slotTest()));
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
void MainWindow::getBucketTest()
{
    // 初始化
    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
    Aws::InitAPI(options);
 
    Aws::Client::ClientConfiguration cfg;
    cfg.endpointOverride = "play.min.io";//官方测试服务器
    cfg.scheme = Aws::Http::Scheme::HTTPS;  //https协议
    //cfg.verifySSL = false;
 
    Aws::Auth::AWSCredentials cred("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
 
 
    Aws::S3::S3Client client(cred, cfg, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Always, false,
                             Aws::S3::US_EAST_1_REGIONAL_ENDPOINT_OPTION::NOT_SET);
 
    auto response = client.ListBuckets();
 
    if (response.IsSuccess()) {
        auto buckets = response.GetResult().GetBuckets();
        for (auto iter = buckets.begin(); iter != buckets.end(); ++iter) {
            cout << iter->GetName() << "\t" << iter->GetCreationDate().ToLocalTimeString(Aws::Utils::DateFormat::ISO_8601) << endl;
        }
    }
 
}
 
 
void MainWindow::slotTest()
{
    qDebug() << "MainWindow::slotTest=========================";
    getBucketTest();
}
 
 
 
 
 

测试结果;

官网桶列表

 参考:

GitHub - aws/aws-sdk-cpp: AWS SDK for C++

https://github.com/minio/minio-cpp

在windows下使用Qt连接minio_minio-cpp-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值