为什么使用AWS SDK for C ++创建EC2Client segfault实例?

时间:2018-04-14 07:55:50

标签: c++ aws-sdk

我正在尝试使用适用于C ++的AWS开发工具包。我有一个小样本程序在尝试创建EC2Client实例时崩溃。

#include <aws/core/Aws.h>
#include <aws/ec2/EC2Client.h>
#include <aws/ec2/model/DescribeInstancesRequest.h>
#include <aws/ec2/model/DescribeInstancesResponse.h>
#include <iostream>
#include <iomanip>


int main (int argc, char *argv [])
{
    Aws::EC2::EC2Client ec2;    
    Aws::EC2::Model::DescribeInstancesRequest request;
    return 0;
}

程序段错误在Aws::EC2::EC2Client ec2;行,但我似乎无法弄清楚原因。

我试图将我的应用程序链接到两个libaws的共享库 - cpp-sdk-corecpp-sdk-ec2以及静态链接。所以它似乎与其他东西有关。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我建议您在阅读其手册时开始使用任何新工具包。

使用AWS开发工具包和C ++的所有代码至少应具有以下内容:

class Runner {
  constructor(maxCount = 1) {
    this.taskQueue = [];
    this.maxCount = maxCount;
    this.currentCount = 0;
  }

  run() {
    if (this.taskQueue.length && this.currentCount < this.maxCount) {
      const task = this.taskQueue.shift();
      task();
    }
  }

  push(task, callback) {
    this.taskQueue.push(() => {
      this.currentCount++;
      task((...args) => {
        this.currentCount--;
        callback(...args);
        this.run();
      })
    })
    this.run();
  }
}

// Example usage
const myCallback = (caller) => {
  console.log(`myCallback called by ${caller} ${new Date()}`);
};

const task1 = (callback) => {
  console.log(`task1 started ${new Date()}`);
  setTimeout(() => {
    callback('task1');
  }, 3000);
};

const task2 = (callback) => {
  console.log(`task2 started ${new Date()}`);
  setTimeout(() => {
    callback('task2');
  }, 3000);
};

const task3 = (callback) => {
  console.log(`task3 started ${new Date()}`);
  setTimeout(() => {
    callback('task3');
  }, 3000);
};

const task4 = (callback) => {
  console.log(`task4 started ${new Date()}`);
  setTimeout(() => {
    callback('task4');
  }, 3000);
};

const runner = new Runner(2);
runner.push(task1, myCallback);
runner.push(task2, myCallback);
runner.push(task3, myCallback);
runner.push(task4, myCallback);