0

so I am trying to upload a local file to aws s3 using the aws sdk cpp. Here is the sample code that I took from an issue here

#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <iostream>
#include <fstream>

using namespace Aws::S3::Model;
using namespace std;
using namespace Aws::Utils;

 static const char* KEY = "try.txt";
 static const char* BUCKET = "bucket-name";

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

Aws::Client::ClientConfiguration myConf;
myConf.region = Aws::Region::US_EAST_2;
Aws::S3::S3Client s3_client(myConf);

const Aws::String bucket_name = BUCKET;
const Aws::String key_name = KEY;
const Aws::String dir_name = "C:/Users/linda.naoui/source/repos/Upload s3";

std::cout << "Uploading " << key_name << " to S3 bucket: " <<
    bucket_name << std::endl;



Aws::S3::Model::PutObjectRequest object_request;
object_request.WithBucket(bucket_name).WithKey(key_name);

auto input_data = Aws::MakeShared<Aws::FStream>(key_name.c_str(), dir_name.c_str(), std::ios_base::in);

object_request.SetBody(input_data);

auto put_object_outcome = s3_client.PutObject(object_request);

if (put_object_outcome.IsSuccess()) {
    std::cout << "Done!" << std::endl;
}
else {
    std::cout << "PutObject error: " <<
        put_object_outcome.GetError().GetExceptionName() << " " <<
        put_object_outcome.GetError().GetMessage() << std::endl;
}

Aws::ShutdownAPI(options);

return 0;
  }

I have a lot of similar errors all related to the dll import, I am installed the aws s3 sdk and aws sdk core using Nuget Package and I am currently on Visual Studio 2019.

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall Aws::S3::Model::PutObjectResult::~PutObjectResult(void)" (__imp_??1PutObjectResult@Model@S3@Aws@@QAE@XZ) referenced in function "public: __thiscall Aws::Utils::Outcome >::~Outcome >(void)" (??1?$Outcome@VPutObjectResult@Model@S3@Aws@@V?$AWSError@W4S3Errors@S3@Aws@@@Client@4@@Utils@Aws@@QAE@XZ) Upload s3 C:\Users\linda.naoui\source\repos\Upload s3\Upload s3\S3.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl Aws::InitAPI(struct Aws::SDKOptions const &)" (__imp_?InitAPI@Aws@@YAXABUSDKOptions@1@@Z) referenced in function _main Upload s3 C:\Users\linda.naoui\source\repos\Upload s3\Upload s3\S3.obj 1

I am not sure if the problem is because the linkage window is empty

enter image description here

Linda Naoui
  • 147
  • 13
  • When having a link error, it's usually a good idea to also show how you link the library, – Rinat Veliakhmedov Jan 21 '20 at 09:45
  • I don't understand what you mean by that, I used nuget to install the sdk's it should link it automatically right? – Linda Naoui Jan 21 '20 at 09:48
  • 1
    What happens if you change it to static linking? – Rinat Veliakhmedov Jan 21 '20 at 09:58
  • Okay so now I no longer have dll errors, but I have LNK2001 unresolved external symbol "public: __cdecl Aws::S3::Model::PutObjectRequest::PutObjectRequest(void)" (??0PutObjectRequest@Model@S3@Aws@@QEAA@XZ) Upload s3 C:\Users\linda.naoui\source\repos\Upload s3\Upload s3\S3.obj 1 They all start with unresolved external symbol – Linda Naoui Jan 21 '20 at 10:03
  • Does this answer help? https://stackoverflow.com/questions/37411546/aws-c-sdk-linker-error-on-visual-studio – Rinat Veliakhmedov Jan 21 '20 at 10:09
  • Actually it didn't resolve my problem, I still have LNK2001 unresolved external symbol "public: __cdecl Aws::Client::ClientConfiguration::ClientConfiguration(void) – Linda Naoui Jan 21 '20 at 10:28

1 Answers1

2

I resolved the issue by uninstalling Visual Studio 2019 and using Visual Studio 2017 instead

Linda Naoui
  • 147
  • 13