Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bgav opened this issue May 15, 2024 · 5 comments
Closed

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

bgav opened this issue May 15, 2024 · 5 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@bgav
Copy link

bgav commented May 15, 2024

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

@bgav bgav added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 15, 2024
@jmklix jmklix self-assigned this May 15, 2024
@jmklix
Copy link
Member

jmklix commented May 15, 2024

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;
}

@jmklix
Copy link
Member

jmklix commented May 15, 2024

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.

@jmklix jmklix added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels May 15, 2024
@bgav
Copy link
Author

bgav commented May 16, 2024

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
Copy link
Author

bgav commented May 16, 2024

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

@bgav bgav closed this as completed May 16, 2024
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

2 participants