aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.96k stars 1.05k forks source link

AWSSDKCPP with Visual Studio 2017 failure #802

Closed JasonLukose closed 6 years ago

JasonLukose commented 6 years ago

Using windows 10, with Visual Studio 2017.

I used Nuget to get the SDK and tried running this:

/*
Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
This file is licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License. A copy of
the License is located at
http://aws.amazon.com/apache2.0/
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
*/
#include <aws/core/Aws.h>
//#include <aws/sqs/SQSClient.h>
//#include <aws/sqs/model/SendMessageRequest.h>
//#include <aws/sqs/model/SendMessageResult.h>
#include <iostream>

/**
* Sends a message to an sqs queue based on command line input
*/
int main(int argc, char** argv)
{
    if (argc != 3)
    {
        std::cout << "Usage: send_message <queue_url> <message_body>" <<
            std::endl;
        return 1;
    }

    Aws::SDKOptions options;
    Aws::InitAPI(options);
    /*{
        Aws::String queue_url = argv[1];
        Aws::String msg_body = argv[2];

        Aws::SQS::SQSClient sqs;

        Aws::SQS::Model::SendMessageRequest sm_req;
        sm_req.SetQueueUrl(queue_url);
        sm_req.SetMessageBody(msg_body);

        auto sm_out = sqs.SendMessage(sm_req);
        if (sm_out.IsSuccess())
        {
            std::cout << "Successfully sent message to " << queue_url <<
                std::endl;sss
        }
        else
        {
            std::cout << "Error sending message to " << queue_url << ": " <<
                sm_out.GetError().GetMessage() << std::endl;
        }

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

However, it seems that visual studio has linking errors when trying to do InitAPI and shutdownAPI.

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------ 1>Source.cpp 1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl Aws::InitAPI(struct Aws::SDKOptions const &)" (?InitAPI@Aws@@YAXABUSDKOptions@1@@Z) referenced in function _main

1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl Aws::ShutdownAPI(struct Aws::SDKOptions const &)" (?ShutdownAPI@Aws@@YAXABUSDKOptions@1@@Z) referenced in function _main

1>C:\Users\Jason\source\repos\Project1\Debug\Project1.exe : fatal error LNK1120: 2 unresolved externals 1>Done building project "Project1.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

There does not seem to be any documentation with Visual Studio 2017

JasonLukose commented 6 years ago

Update: it works with VS2015.

singku commented 6 years ago

Thanks for reporting this problem. Some of the Nuget packages for vs2017 are missing, we fixed it. It will be available on Nuget soon.

singku commented 6 years ago

Hi, Nuget packages for vs2017 has been updated, Thank you!

JasonLukose commented 6 years ago

Thanks! It works great. I did have to make the reference packages statically linked and not dynamically linked after I re installed the core and sqs. All in all, works well!

singku commented 6 years ago

@JasonLukose What will happen when you dynamically link the libs?

JasonLukose commented 6 years ago

It will error with the following error if both are DLL @singku

Error   LNK2001 unresolved external symbol "char const * const Aws::Http::CONTENT_TYPE_HEADER"
(?CONTENT_TYPE_HEADER@Http@Aws@@3PEBDEB)        

Sorry, saw this late! @singku

singku commented 6 years ago

@JasonLukose We compiled above code with vs2017 and Nuget package, both dynamic and static link can work just fine. By the way, we select the link method in "Propoerties->Referenced Packages"