Statically link Hello S3 App with sdk libraries #2384
-
Hello, I am following the guide here: https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/build-cmake.html and am trying to statically link the c++ sdk libraries, as I intend to run the binary on a platform where I know the shared libraries will not be available (and I am additionally unable to install them on that platform). Compilation works fine with shared libraries. How can I go about doing this in the I have compiled the SDK with both -DFORCE_SHARED_CRT=OFF and -DBUILD_SHARED_LIBS=OFF as well. When I try to compile
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Can you trying cleaning up your user directory before trying to do a fresh static install? I wasn't able to reproduce the error that you are seeing and I ran the following commands: mkdir build_static
cd build_static
cmake .. -DBUILD_ONLY="s3-crt;s3" -DCMAKE_BUILD_TYPE=Debug -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF
make
make install
cd ..
mkdir sdk_static_test
cd sdk_static_test
vim CMakeLists.txt
vim main.cpp
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
./sdk_static_test CMakeLists.txt cmake_minimum_required(VERSION 3.21)
project(sdk_static_test)
set(CMAKE_CXX_STANDARD 23)
find_package(AWSSDK REQUIRED COMPONENTS s3)
find_package(ZLIB QUIET)
add_executable(sdk_static_test main.cpp)
set_compiler_flags(${PROJECT_NAME})
set_compiler_warnings(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES}) main.cpp #include <aws/core/Aws.h>
#include <aws/core/utils/logging/LogLevel.h>
#include <aws/s3/S3Client.h>
#include <iostream>
using namespace Aws;
int main()
{
//The Aws::SDKOptions struct contains SDK configuration options.
//An instance of Aws::SDKOptions is passed to the Aws::InitAPI and
//Aws::ShutdownAPI methods. The same instance should be sent to both methods.
SDKOptions options;
options.loggingOptions.logLevel = Utils::Logging::LogLevel::Debug;
//The AWS SDK for C++ must be initialized by calling Aws::InitAPI.
InitAPI(options);
{
S3::S3Client client;
auto outcome = client.ListBuckets();
if (outcome.IsSuccess()) {
std::cout << "Found " << outcome.GetResult().GetBuckets().size() << " buckets\n";
for (auto&& b : outcome.GetResult().GetBuckets()) {
std::cout << b.GetName() << std::endl;
}
}
else {
std::cout << "Failed with error: " << outcome.GetError() << std::endl;
}
}
//Before the application terminates, the SDK must be shut down.
ShutdownAPI(options);
return 0;
} |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hi, thank you for the response! I did manage to solve the error by moving the libraries to a specific folder, then setting -DCMAKE_PREFIX_PATH=.