Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation errors for file upload via S3Client PutObject in C++ on Mac #1168

Closed
tedyu opened this issue Jun 12, 2019 · 2 comments
Closed

Compilation errors for file upload via S3Client PutObject in C++ on Mac #1168

tedyu opened this issue Jun 12, 2019 · 2 comments
Assignees
Labels
guidance Question that needs advice or information.

Comments

@tedyu
Copy link

tedyu commented Jun 12, 2019

What platform/OS are you using?

Darwin 17.7.0 Darwin Kernel Version 17.7.0: Wed Apr 24 21:17:24 PDT 2019; root:xnu-4570.71.45~1/RELEASE_X86_64 x86_64

Which version of the SDK?

master branch of aws-sdk-cpp repo

What compiler are you using? what version?

gcc

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

What are your CMake arguments?

cmake -Wc++11-extensions -I/Users/yute/homebrew/include -L/Users/yute/homebrew/lib/cmake –Daws-sdk-cpp_DIR=~/aws-sdk-cpp/build .

Can you provide a TRACE level log? (sanitize any sensitive information)

/Users/yute/ccs-us-west/triton/native/s3-upl-retrieve.cpp:35:46: error: no viable conversion from 'shared_ptr<std::__1::basic_fstream<char, std::__1::char_traits<char> >>' to 'const shared_ptr<Aws::IOStream>'
        const std::shared_ptr<Aws::IOStream> input_data =
                                             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3703:23: note: candidate constructor not viable: no known conversion from 'std::shared_ptr<basic_fstream<char, char_traits<char> > >' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
                      ^

Here is the program

#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 = "AKIAYUP244WDQOLCSQEK";
static const char* BUCKET = "hcs-poc-dev";

int main()
{
    Aws::SDKOptions options;
    Aws::Client::ClientConfiguration client_configuration;
    client_configuration.region = Aws::Region::US_EAST_2;
    Aws::InitAPI(options);
	{
		S3Client client(client_configuration);

		//first put an object into s3
		PutObjectRequest putObjectRequest;
		putObjectRequest.WithKey(KEY)
			   .WithBucket(BUCKET);

		//this can be any arbitrary stream (e.g. fstream, stringstream etc...)
        std::string file_name("s3-sample");
        const std::shared_ptr<Aws::IOStream> input_data =
            Aws::MakeShared<Aws::FStream>("SampleAllocationTag",
                                      file_name.c_str(),
                                      std::ios_base::in | std::ios_base::binary);
        putObjectRequest.SetBody(input_data);
		auto putObjectOutcome = client.PutObject(putObjectRequest);

		if(putObjectOutcome.IsSuccess())
		{
			std::cout << "Put object succeeded" << std::endl;
		}
@tedyu
Copy link
Author

tedyu commented Jun 12, 2019

In file included from /Users/yute/ccs-us-west/triton/native/s3-upl-retrieve.cpp:1:
In file included from /Users/yute/homebrew/include/aws/s3/S3Client.h:19:
In file included from /Users/yute/homebrew/include/aws/core/client/AWSError.h:19:
In file included from /Users/yute/homebrew/include/aws/core/utils/memory/stl/AWSString.h:20:
In file included from /Users/yute/homebrew/include/aws/core/utils/memory/stl/AWSAllocator.h:21:
In file included from /Users/yute/homebrew/include/aws/core/utils/memory/AWSMemory.h:22:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:652:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/type_traits:3141:38: error: implicit instantiation of undefined template 'std::__1::basic_fstream<char, std::__1::char_traits<char> >'
    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:4290:20: note: in instantiation of template class 'std::__1::is_constructible<std::__1::basic_fstream<char, std::__1::char_traits<char> >, const char *, unsigned int>' requested here
    static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
...
In file included from /Users/yute/homebrew/include/aws/core/utils/memory/AWSMemory.h:22:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:4290:5: error: static_assert failed due to requirement 'is_constructible<basic_fstream<char, char_traits<char> >, const char *, unsigned int>::value' "Can't construct object in allocate_shared"
    static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
    ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:4668:29: note: in instantiation of function template specialization 'std::__1::shared_ptr<std::__1::basic_fstream<char, std::__1::char_traits<char> > >::allocate_shared<Aws::Allocator<std::__1::basic_fstream<char, std::__1::char_traits<char> > >, const char *, unsigned int>' requested here
    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
                            ^

@KaibaLopez KaibaLopez added the guidance Question that needs advice or information. label Jun 13, 2019
@KaibaLopez KaibaLopez self-assigned this Jun 13, 2019
@KaibaLopez
Copy link
Contributor

KaibaLopez commented Jun 13, 2019

Hi @tedyu , please include fstream on your code and that should take care of the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants