Reputation: 101
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:
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.
Upvotes: 5
Views: 3886
Reputation: 101
Issues and corresponding solutions to them I have found during my build:
Solution: Use AWSSDK in find_package of the CMakeLists.txt to guide us
find_package(AWSSDK REQUIRED COMPONENTS s3)
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/")
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)
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
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
./s3-demo my-test-bucket us-west-2
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