我正在尝试使用amazon aws最近发布的用于c ++的实验性sdk。我的目的是让我的c ++程序从亚马逊SQS检索消息,因此我需要先与SQS建立连接。我是c ++的新手。 我设法编译程序,但在运行时遇到错误
我的代码:
#include <iostream> #include <sstream> #include <iterator> #include <algorithm> #include <string.h> #include <unistd.h> #include <aws/core/client/ClientConfiguration.h> #include <aws/core/client/CoreErrors.h> #include <aws/core/auth/AWSCredentialsProviderChain.h> #include <aws/core/utils/json/JsonSerializer.h> #include <aws/core/utils/xml/XmlSerializer.h> #include <aws/sqs/SQSClient.h> #include <aws/sqs/model/CreateQueueRequest.h> #include <aws/sqs/model/ListQueuesRequest.h> #include <aws/sqs/model/DeleteQueueRequest.h> #include <aws/sqs/model/SendMessageRequest.h> #include <aws/sqs/model/ReceiveMessageRequest.h> #include <aws/sqs/model/DeleteMessageRequest.h> #include <aws/sqs/model/GetQueueAttributesRequest.h> #include <aws/sqs/model/SetQueueAttributesRequest.h> #include <aws/sqs/model/AddPermissionRequest.h> #include <aws/sqs/model/RemovePermissionRequest.h> #include <aws/sqs/model/ListDeadLetterSourceQueuesRequest.h> #include <aws/core/utils/Outcome.h> #include <aws/sqs/model/ChangeMessageVisibilityBatchRequestEntry.h> #include <aws/sqs/model/ChangeMessageVisibilityBatchRequest.h> #include <aws/sqs/model/SendMessageBatchRequestEntry.h> #include <aws/sqs/model/SendMessageBatchRequest.h> #include <memory> using namespace Aws::Http; using namespace Aws; using namespace Aws::Auth; using namespace Aws::Client; using namespace Aws::SQS; using namespace Aws::SQS::Model; using namespace Aws::Utils::Json;
int main(int argc, char** argv) {
//Initialize SQS client
ClientConfiguration config;
config.scheme = Scheme::HTTPS;
config.region = Aws::Region::US_EAST_1; std::unique_ptr<SQSClient> sqsClient(new SQSClient(config)); return 0; }
报告错误:free()无效指针0x00007f5a80eeaa80
快照记录来自valgrind:
1 errors in context 10 of 10: ==22040== Invalid free() / delete / delete[] / realloc() ==22040== at 0x4C2C2BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22040== by 0x5A001BF: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==22040== by 0x40154D: Aws::Client::ClientConfiguration::~ClientConfiguration() (ClientConfiguration.h:53) ==22040== by 0x56D730A: Aws::Internal::EC2MetadataClient::EC2MetadataClient(char const*, std::shared_ptr<Aws::Http::HttpClientFactory const>) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8541: _ZN9__gnu_cxx13new_allocatorIN3Aws8Internal17EC2MetadataClientEE9constructIS3_IEEEvPT_DpOT0_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8406: _ZNSt16allocator_traitsIN3Aws9AllocatorINS0_8Internal17EC2MetadataClientEEEE12_S_constructIS3_IEEENSt9enable_ifIXsrNS5_18__construct_helperIT_IDpT0_EEE5valueEvE4typeERS4_PS9_DpOSA_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8308: _ZNSt16allocator_traitsIN3Aws9AllocatorINS0_8Internal17EC2MetadataClientEEEE9constructIS3_IEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS4_PT_DpOS7_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8110: std::_Sp_counted_ptr_inplace<Aws::Internal::EC2MetadataClient, Aws::Allocator<Aws::Internal::EC2MetadataClient>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<>(Aws::Allocator<Aws::Internal::EC2MetadataClient>) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7DFD: _ZN9__gnu_cxx13new_allocatorISt23_Sp_counted_ptr_inplaceIN3Aws8Internal17EC2MetadataClientENS2_9AllocatorIS4_EELNS_12_Lock_policyE2EEE9constructIS8_IKS6_EEEvPT_DpOT0_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7C00: _ZNSt16allocator_traitsIN3Aws9AllocatorISt23_Sp_counted_ptr_inplaceINS0_8Internal17EC2MetadataClientENS1_IS4_EELN9__gnu_cxx12_Lock_policyE2EEEEE12_S_constructIS8_IKS5_EEENSt9enable_ifIXsrNSA_18__construct_helperIT_IDpT0_EEE5valueEvE4typeERS9_PSF_DpOSG_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7903: _ZNSt16allocator_traitsIN3Aws9AllocatorISt23_Sp_counted_ptr_inplaceINS0_8Internal17EC2MetadataClientENS1_IS4_EELN9__gnu_cxx12_Lock_policyE2EEEEE9constructIS8_IKS5_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS9_PT_DpOSD_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C75F8: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Internal::EC2MetadataClient, Aws::Allocator<Aws::Internal::EC2MetadataClient>>(std::_Sp_make_shared_tag, Aws::Internal::EC2MetadataClient*, Aws::Allocator<Aws::Internal::EC2MetadataClient> const&) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== Address 0x55a3680 is in the BSS segment of /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-sqs.so ==22040== ==22040== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 0 from 0)
答案 0 :(得分:1)
我认为该问题与AWS C ++ SDK中内置的AWS自定义内存管理支持有关。默认情况下,如果您为共享库编译,AWS将启用自定义内存管理。这在osx上工作得很好,但是我在ubuntu 14.04上收到了和你一样的错误
我手动删除了CMakeLists.txt文件中的行add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
,重新编译并运行。