Han
Han

Reputation: 101

Linking issues with AWS SDK

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:

I have used the following commands:

- 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:

https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-cplusplus.html#sample-cplusplus-sdk-code

My CMakeLists.txt that I use:

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:

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:

What I want to know:

  1. 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.

  2. 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?

  3. 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.

Upvotes: 5

Views: 3886

Answers (1)

Han
Han

Reputation: 101

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

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

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

set(BUILD_SHARED_LIBS ON)

Environment

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

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/

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

./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

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

Upvotes: 4

Related Questions