aws/aws-sdk-cpp

Using AWS C++ SDK with gcc-g++11

bgav opened this issue · 5 comments

bgav commented

Describe the bug

Hello,

We are trying to port our solution to Amazon Linux 2023 on AMD and Graviton. As I understand, the only option for C++ development there is default toochain for gcc-g++11.

Following code compiles with devtoolset-10 (RHEL7) and gcc-toolset-13 (RHEL9). It also fails with gcc11 on RHEL9.
Since there is no toolsets option on Linux 2023, we need to make it working with gcc11 environment.
Do you have any idea?

Expected Behavior

Expecting the code compiles

Current Behavior

In file included from /usr/include/c++/11/thread:43,
                 from 3rdParty/aws-sdk-cpp/include/aws/core/utils/logging/DefaultCRTLogSystem.h:11,
                 from 3rdParty/aws-sdk-cpp/include/aws/core/utils/logging/CRTLogSystem.h:56,
                 from 3rdParty/aws-sdk-cpp/include/aws/core/Aws.h:9,
                 from Common/aws_secretsmanager/aws_secretsmanager_t.cpp:10:
/usr/include/c++/11/bits/std_thread.h: In constructor ‘std::thread::thread(_Callable&&, _Args&& ...)’:
/usr/include/c++/11/bits/std_thread.h:145:13: error: cannot convert ‘long int’ to ‘void (*)()’
  145 |             __depend);
      |             ^~~~~~~~
      |             |
      |             long int
/usr/include/c++/11/bits/std_thread.h:215:33: note:   initializing argument 2 of ‘void std::thread::_M_start_thread(std::thread::_State_ptr, void (*)())’
  215 |     _M_start_thread(_State_ptr, void (*)());
      |                                 ^~~~~~~~~~

CPP file excerpt:

  3 #include <aws/secretsmanager/model/GetSecretValueRequest.h>
10 #include <aws/core/Aws.h>
11 #include <aws/secretsmanager/SecretsManagerClient.h>

29 aws_secretsmanager_t::aws_secretsmanager_t(const std::string& region)
30 {
35     options_ = std::make_unique<Aws::SDKOptions>();
36     Aws::InitAPI(*options_);
37     config_ = std::make_unique<Aws::Client::ClientConfiguration>();
38     if (!region.empty()) config_->region = region;
39     sm_client_ = std::make_unique<Aws::SecretsManager::SecretsManagerClient>(*config_);
47 }

H file excerpt

#include <string>
namespace Aws
{
    struct SDKOptions;
    namespace Client { struct ClientConfiguration; }
    namespace SecretsManager { class SecretsManagerClient; }
}
class aws_secretsmanager_t
{
public:
    explicit aws_secretsmanager_t(const std::string& region = "");
private:
    std::unique_ptr<Aws::SDKOptions> options_;
    std::unique_ptr<Aws::Client::ClientConfiguration> config_;
    std::unique_ptr<Aws::SecretsManager::SecretsManagerClient> sm_client_;
};

Reproduction Steps

I think provided code is enough for reproduction

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

1.11

Compiler and Version used

g++ (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)

Operating System and version

Amazon Linux 2023

Can you make sure that you are following our guidelines for using this sdk. Specifically making all sdk calls within brackets {} to make sure that the scope is managed correctly.

#include <aws/core/Aws.h>
int main(int argc, char** argv)
{
   Aws::SDKOptions options;
   Aws::InitAPI(options);
   {
      // make your SDK calls here.
   }
   Aws::ShutdownAPI(options);
   return 0;
}

I was able to setup this docker container that matches the environment you're using:

Dockerfile
FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal

#install deps
RUN dnf install -y git cmake gcc-c++ libcurl-devel zlib-devel openssl-devel

# # Clone repo
RUN git clone --depth 1 --recurse-submodules https://github.com/aws/aws-sdk-cpp && \
    cd aws-sdk-cpp && \
    mkdir build && \
    cd build && \
    cmake -DAUTORUN_UNIT_TESTS=OFF -DBUILD_ONLY="secretsmanager" .. && \
    cmake --build . && \
    cmake --install .

# Copy Code Over \
RUN mkdir sdk-example
COPY CMakeLists.txt sdk-example/CMakeLists.txt
COPY main.cpp sdk-example/main.cpp
RUN cd sdk-example && \
    mkdir build && \
    cd build && \
    cmake .. && \
    cmake --build .

ENTRYPOINT [ "./sdk-example/build/sdk_example" ]
main.cpp
#include <iostream>
#include <aws/core/Aws.h>
#include <aws/secretsmanager/SecretsManagerClient.h>

using namespace std;
using namespace Aws;

int main() {
    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;

    Aws::InitAPI(options);
    {
      cout << "test setting up SecretsManagerClient" << endl;
      auto config_ = std::make_unique<Aws::Client::ClientConfiguration>();
      config_->region = "us-east-1";
      auto sm_client_ = std::make_unique<Aws::SecretsManager::SecretsManagerClient>(*config_);
    }
    Aws::ShutdownAPI(options);
    return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(sdk_example)
set(CMAKE_CXX_STANDARD 20)
find_package(AWSSDK REQUIRED COMPONENTS secretsmanager)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})

To run this put all three files in one folder and run the following commands:

  • docker build -t amzlinux2023 .
  • docker run --name amzlinux2023_container amzlinux2023

Please let me know if you still have any problems with using this sdk.

bgav commented

Thanks for your advice, Joseph.
I'll review our code upon it and let you know.
It was strange for me, that it compiles with other gcc toolchains and also VS2022.

bgav commented

I found the issue in our environment. Compilation issue resolved.
Thanks a lot for your time and efforts.

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.