1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

aws-sdk-cpp の使い方

Last updated at Posted at 2018-02-10

今の時点では失敗の報告です。代替案も用意しました。

Git からクローンします。

git clone https://github.com/aws/aws-sdk-cpp.git

ライブラリの作成

mkdir build_dir
cd build_dir/
cmake ../aws-sdk-cpp -DBUILD_ONLY="s3"
make

make の結果はこのようになります。

[----------] 11 tests from DefaultRateLimitTest
[ RUN      ] DefaultRateLimitTest.nopTest
[       OK ] DefaultRateLimitTest.nopTest (0 ms)
[ RUN      ] DefaultRateLimitTest.trivialTest
[       OK ] DefaultRateLimitTest.trivialTest (0 ms)
[ RUN      ] DefaultRateLimitTest.limitEdgeTest
[       OK ] DefaultRateLimitTest.limitEdgeTest (0 ms)
[ RUN      ] DefaultRateLimitTest.doubleLimitTest
[       OK ] DefaultRateLimitTest.doubleLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.delayedLimitEdgeLimitTest
[       OK ] DefaultRateLimitTest.delayedLimitEdgeLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.delayedOverLimitTest
[       OK ] DefaultRateLimitTest.delayedOverLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.twoDelayOverLimitTest
[       OK ] DefaultRateLimitTest.twoDelayOverLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.longDelayLimitTest
[       OK ] DefaultRateLimitTest.longDelayLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.renormalizedChangeRateLimitTest
[       OK ] DefaultRateLimitTest.renormalizedChangeRateLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.unnormalizedChangeRateLimitTest
[       OK ] DefaultRateLimitTest.unnormalizedChangeRateLimitTest (0 ms)
[ RUN      ] DefaultRateLimitTest.fractionalLimitTest
[       OK ] DefaultRateLimitTest.fractionalLimitTest (0 ms)
[----------] 11 tests from DefaultRateLimitTest (0 ms total)

[----------] Global test environment tear-down
[==========] 270 tests from 43 test cases ran. (1518 ms total)
[  PASSED  ] 270 tests.
[100%] Built target aws-cpp-sdk-core-tests

次は、出来ています。

aws-cpp-sdk-core/libaws-cpp-sdk-core.so
aws-cpp-sdk-s3/libaws-cpp-sdk-s3.so
testing-resources/libtesting-resources.so

次のようなサンプルをコンパイルしてみます。

ex01.cpp
// -----------------------------------------------------------------------
/*
	ex01.cpp

					Feb/11/2018
*/
// -----------------------------------------------------------------------
# include <aws/s3/S3Client.h>
# include <aws/s3/model/PutObjectRequest.h>
# include <aws/s3/model/GetObjectRequest.h>
# include <aws/core/Aws.h>
# include <aws/core/utils/memory/stl/AWSStringStream.h> 

using namespace Aws::S3;
using namespace Aws::S3::Model;

static const char* KEY = "s3_cpp_sample_key";
static const char* BUCKET = "s3-cpp-sample-bucket";

// -----------------------------------------------------------------------
int main()
{
    Aws::SDKOptions options;
    Aws::InitAPI(options);


    Aws::ShutdownAPI(options);
    return 0;  
}

// -----------------------------------------------------------------------

Makefile です。

Makefile
#
SRC_DIR=/home/uchida/lang/cpp
ex01: ex01.cpp
	c++ -o ex01 ex01.cpp \
	-I $(SRC_DIR)/aws-sdk-cpp/aws-cpp-sdk-core/include \
	-I $(SRC_DIR)/aws-sdk-cpp/aws-cpp-sdk-s3/include \
	-L $(SRC_DIR)/build_dir/aws-cpp-sdk-core \
	-L $(SRC_DIR)/build_dir/aws-cpp-sdk-s3 \
	-L $(SRC_DIR)/build_dir/testing-resources \
	-DUSE_IMPORT_EXPORT
clean:
	rm -f ex01.o ex01

コンパイルは通るのですがリンクでエラーになります。

$ make
c++ -o ex01 ex01.cpp \
-I /home/uchida/lang/cpp/aws-sdk-cpp/aws-cpp-sdk-core/include \
-I /home/uchida/lang/cpp/aws-sdk-cpp/aws-cpp-sdk-s3/include \
-L /home/uchida/lang/cpp/build_dir/aws-cpp-sdk-core \
-L /home/uchida/lang/cpp/build_dir/aws-cpp-sdk-s3 \
-L /home/uchida/lang/cpp/build_dir/testing-resources \
-DUSE_IMPORT_EXPORT
/tmp/ccADbN4R.o: 関数 `main' 内:
ex01.cpp:(.text+0x35): `Aws::InitAPI(Aws::SDKOptions const&)' に対する定義されていない参照です
ex01.cpp:(.text+0x44): `Aws::ShutdownAPI(Aws::SDKOptions const&)' に対する定義されていない参照です
collect2: エラー: ld はステータス 1 で終了しました
make: *** [Makefile:4: ex01] エラー 1

暫定対策として、system() 関数で python のプログラムをコールすることにしました。

python のプログラムです。

list-buckets.py
# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	list-buckets.py
#
#					Feb/11/2018
#
# ------------------------------------------------------------------
import boto3

s3 = boto3.client('s3')

response = s3.list_buckets()

buckets = [bucket['Name'] for bucket in response['Buckets']]

print("Bucket List: %s" % buckets)
# ------------------------------------------------------------------

c++ のプログラムです。

system_python.cpp
// -----------------------------------------------------------------------
/*
	system_python.cpp

						Feb/11/2018
*/
// -----------------------------------------------------------------------
# include <iostream>
# include <cstdlib>

// -----------------------------------------------------------------------
using namespace std;
// -----------------------------------------------------------------------
int main (int argc, char* argv[])
{
	cerr << "*** 開始 ***\n";

	system("./list-buckets.py");

	cerr << "*** 終了 ***\n";

	return 0;
}

// -----------------------------------------------------------------------

Makefile です。

Makefile
system_python: system_python.cpp
	clang++ -o system_python system_python.cpp
clean:
	rm -f system_python

コンパイルして実行です。

make
./system_python
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?