Question:
I have limited knowledge in AWS SDK and Linux, but I have been reading into GCC and CMake syntax and trying to get myself to compile and run the sample on AWS https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-cplusplus.html#sample-cplusplus-sdk. Here is my second attempt at tackling this problem.
This is the environment I am running:
- AWS Linux Cloud 9
- gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
- GNU Make 3.82
- cmake3 version 3.6.1
I have used the following commands:
1 2 3 4 5 6 7 8 |
- sudo yum -y install libcurl-devel openssl-devel libuuid-devel cmake3 - git clone https://github.com/aws/aws-sdk-cpp.git - mkdir sdk_build - cd sdk_build - cmake3 ../aws-sdk-cpp -DBUILD_ONLY="s3" - sudo make - sudo make install |
Building and run of AWS SDK Code:
1 2 |
https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-cplusplus.html#sample-cplusplus-sdk-code |
My CMakeLists.txt that I use:
1 2 3 4 5 6 7 |
cmake_minimum_required(VERSION 2.8) project(s3-demo) find_package(aws-sdk-cpp) add_definitions(-DUSE_IMPORT_EXPORT) add_executable(s3-demo s3-demo.cpp) target_link_libraries(s3-demo aws-cpp-sdk-s3) |
My modules/directories:
1 2 3 4 5 6 7 8 |
environment - .c9 - aws-sdk-cpp #This is the git source DIR - sdk_build #This is the build DIR - CMakeLists.txt (see above) - hello.cpp - hello.cpp.o |
The Issue:
Many undefined references, here is a snippet:
- Aws::Client::ClientConfiguration::ClientConfiguration()
- Aws::InitAPI(Aws::SDKOptions const&)
- Aws::S3::S3Client::S3Client(Aws::Client::ClientConfiguration const&, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy, bool, Aws::S3::US_EAST_1_REGIONAL_ENDPOINT_OPTION)
- undefined reference to `Aws::S3::S3Client::~S3Client()
- Some linking issues with Aws::Client::AWSClient::AWSClient(Aws::Client::AWSClient const&)
What I want to know:
- I know that -L helps to identify the shared library folder that I want to use, and -l the shared file I want to use. However, I have read that when building the AWS project above per instructions on the website, the targets and flags should auto-populate and I should not need to do any special linking to get this project working.
- It looks like the aws-cpp-sdk-core and aws-cpp-sdk-s3 are in my source folder aws-sdk-cpp. Should this be in my build folder sdk_build? Did I compile my project correctly?
- How do I build a successful out of source folder aws-sdk-cpp and should I build an in-source folder within aws-sdk-cpp?
Any assistance with my problem is appreciated.
Answer:
Issues and corresponding solutions to them I have found during my build:
1. Undefined linker issues and unable to find dependencies from sdk_build.
Solution: Use AWSSDK in find_package of the CMakeLists.txt to guide us
1 2 |
find_package(AWSSDK REQUIRED COMPONENTS s3) |
2. Cmake build errors stating Cmake cannot find aws-sdk-cpp files such as aws-sdk-cpp-config.cmake, aws-c-event-stream-config.cmake.
Solution: AWS SDK looks for the binary and includes folders from the install path of sdk_build as per AWSSDKConfig.cmake. We shall add into ~/environment/CMakeLists.txt the following
1 2 |
set(AWSSDK_ROOT_DIR, "/usr/local/") |
3. Cmake build states that it is looking for static libraries when shared libs have been built during the install of sdk_build.
Solution: The CMakeLists.txt from aws-sdk-cpp builds into sdk_build as shared libs, looks like shared libs flag has not been turned on during linking, therefore it looks for static libs, we need to turn this on
1 2 |
set(BUILD_SHARED_LIBS ON) |
Environment
1 2 3 4 5 |
AWS Linux Cloud 9 gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) GNU Make 3.82 cmake3 version 3.6.1 |
Commands that I used to build C++ Sample:
Install required Tools
1 2 3 |
sudo yum -y install gcc72 gcc72-c++ sudo yum -y install libcurl-devel openssl-devel libuuid-devel cmake3 |
Building project on home/ec2-user/environment/
1 2 3 4 5 6 7 8 9 10 11 |
git clone https://github.com/aws/aws-sdk-cpp.git cd aws-sdk-cpp mkdir sdk_build cd sdk_build cmake3 .. -DBUILD_ONLY=s3 sudo make install cd .. create CMakeLists.txt and s3-demo.cpp here (see below) cmake3 . make |
Tested output of executable s3-demo in terminal with
1 2 |
./s3-demo my-test-bucket us-west-2 |
Files needed in /home/ec2-user/environment/
s3-demo.cpp
get your code in this link
CMakeLists.txt
1 2 3 4 5 6 7 8 |
cmake_minimum_required(VERSION 3.5) project(s3-demo) set(AWSSDK_ROOT_DIR, "/usr/local/") set(BUILD_SHARED_LIBS ON) find_package(AWSSDK REQUIRED COMPONENTS s3) add_executable(s3-demo s3-demo.cpp) target_link_libraries(s3-demo ${AWSSDK_LINK_LIBRARIES}) |