aws / aws-sdk-cpp

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

Exception Thrown at aws-cpp-sdk-core.dll on x64 msvc build #1194

Closed ThanasisPap closed 5 years ago

ThanasisPap commented 5 years ago

After building the SDK for x64 bit architecture and implement a basic operational example, the program crashes with an Access violation writing location exception. The crash happens on the closing scope operator just before

Aws::ShutdownAPI(options);

command.

The corresponding error happens only on x64 builds both with Custom Build Sequence and Vcpkg using:

vcpkg install aws-sdk-cpp[core,s3,rds]:x64-windows

For x86 Builds (with the corresponding msvc compiler) the application runs successfully.

What platform/OS are you using?

Windows 10 x64

Which version of the SDK?

Version 2.0

What compiler are you using? what version?

Visual Studio 15 2017 Win64

What are your CMake arguments?

cmake -G "Visual Studio 15 Win64" -DMINIMIZE_SIZE=ON -DBUILD_ONLY="s3;rds;" -DCMAKE_BUILD_TYPE=Debug

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

The debugger stops at line 222 at xutility with the message:

Exception thrown at 0x00007FFD842D5C4D (aws-cpp-sdk-core.dll) in TestAWS_x64BUG.exe: 0xC0000005: Access violation writing location 0x00000000DDDDDDDD.

I'm also posting a minimal code snippet to reproduce:

#include "pch.h"
#include <iostream>

#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/s3/model/Object.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/s3/model/HeadBucketRequest.h>
#include <aws/s3/model/PutObjectRequest.h>

static const char* KEY = "KEY";
static const char* ACCESS_KEY = "ACCESS_KEY";

int main()
{
    Aws::SDKOptions options;
    Aws::InitAPI(options);
    {
        Aws::Client::ClientConfiguration config;
        config.region = Aws::Region::US_EAST_2;
        Aws::S3::S3Client s3_client(Aws::Auth::AWSCredentials(KEY, ACCESS_KEY), config);
    } //CRASH POINT
    Aws::ShutdownAPI(options);

    return 0;
}

*Note that I have already define:

USE_IMPORT_EXPORT;

USE_WINDOWS_DLL_SEMANTICS;

KaibaLopez commented 5 years ago

Hi @ThanasisPap, I noticed you posted another issue not too long after this one ( #1195 ), where you built your project on the same environment, is it safe to assume that you were able to solve this problem?

ThanasisPap commented 5 years ago

Hi @KaibaLopez , I am working on 32bit compiler on #1195. I'll correct the post accordingly.

KaibaLopez commented 5 years ago

Hi @ThanasisPap , I'm trying to reproduce this error but having some problems. In my experience dll access violation errors such as these are commonly due to trying to use a dll file created for a different build, like referencing a dll generated for debug for a release build or win32 for a x64, etc. Could you check that the dlls in the output folder(TestAWS_x64BUG/x64/Debug) are the correct ones?

ThanasisPap commented 5 years ago

@KaibaLopez , The issue solved after replacing the include folder with the Vpckg one. It seems that a code error caused the problem and not a linking mismatch.
Thanks!

chris-gong commented 5 years ago

I experienced this issue as well when I updated my dll and lib files, but forgot to update my include folders so they were still pointing to an older version. Updating the include folders did the trick!

GitZinger commented 3 years ago

I experienced this issue as well when I updated my dll and lib files, but forgot to update my include folders so they were still pointing to an older version. Updating the include folders did the trick!

@chris-gong I am having this trouble as well. I think I used the source to built it. So the include folders are from the source code. and I copy the dll to the executable folders and linked to the build lib folders. could you tell me how to fix this trouble? thank you

chris-gong commented 3 years ago

I personally didn't experience this issue when the dll and lib files, and include files came from the same source code version.

GitZinger commented 3 years ago

I really stuck here! Did you try the lastest version? I used visual studio gui to build the souce code. Could you help me here lead me out of this pain please? Thank you so much! @chris-gong

chris-gong commented 3 years ago

Going to be honest, I haven't done this in over a year so I don't remember much.

shivanshtech commented 3 years ago

The concerned error is shown in VS2013 but is working fine in VS2017, can anyone tell how to work this in vs2013 as my entire work is in visual studio 2013 and can't upgrade to higher version

shivanshtech commented 3 years ago

@GitZinger @chris-gong @ThanasisPap can anyone help me with this? "The concerned error is shown in VS2013 but is working fine in VS2017, can anyone tell how to work this in vs2013 as my entire work is in visual studio 2013 and can't upgrade to higher version"

ThanasisPap commented 3 years ago

@shivanshtech the issue seems to be solved when you also update the corresponding include folder accordingly after building the SDK. Also make sure that you have already defined:

USE_IMPORT_EXPORT; USE_WINDOWS_DLL_SEMANTICS;

shivanshtech commented 3 years ago

I have compiled the sdk in vs2017 win64 and want to use the dlls on visual studio 2013 but not able to do, showing above exception. I could not understand the meaning of " update the corresponding include folder accordingly after building the SDK" @ThanasisPap

ThanasisPap commented 3 years ago

@shivanshtech You can either build the SDK from source or use Vcpkg (see here). For both solutions you must not only copy the library files but also the include folder containing the corresponding headers.

These folders are placed in sources directory in the corresponding modules accordingly. For example the s3 headers are placed in: aws-sdk-cpp/aws-cpp-sdk-s3/include/aws/s3/ You must copy these headers to your build directory.

PS: I have to say that I finally used the second approach (Vcpkg) to get a working solution. This doesn't mean that you also have to do it that way.

shivanshtech commented 3 years ago

Followed the above mentioned step, getting these errors now. [12:50, 1/15/2021] Laughwithshivansh: Error 1 error C2039: 'SDKOptions' : is not a member of 'Aws' D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 25 1 SecretsManagerTestApp2013 Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 25 1 SecretsManagerTestApp2013 Error 3 error C2146: syntax error : missing ';' before identifier 'Options' D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 25 1 SecretsManagerTestApp2013 Error 4 error C2065: 'Options' : undeclared identifier D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 25 1 SecretsManagerTestApp2013 Error 5 error C2039: 'InitAPI' : is not a member of 'Aws' D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 27 1 SecretsManagerTestApp2013 Error 6 error C2065: 'Options' : undeclared identifier D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 27 1 SecretsManagerTestApp2013 Error 7 error C3861: 'InitAPI': identifier not found D:\Shivansh\SecretsManagerTestApp2013\SecretsManagerTestApp2013\SM1.cpp 27 1 SecretsManagerTestApp2013

shivanshtech commented 3 years ago

@ThanasisPap at run time i'm getting system errors for example-

  1. MSVCP140D.dll was not found, reinstalling the program may fix this problem.
  2. VCRUNTIME140D.dll was not found etc.
shivanshtech commented 3 years ago

I downloaded all the dlls individually , also installed Redistributable again , getting error "The application was unable to start correctly") @ThanasisPap

shivanshtech commented 3 years ago

Again back to where I started, showing above core.dll msvc build error. I followed both of your steps @ThanasisPap

ThanasisPap commented 3 years ago

@shivanshtech Please define your problem clearly. This thread is opened regarding the following error:

Exception thrown at 0x00007FFD842D5C4D (aws-cpp-sdk-core.dll) in TestAWS_x64BUG.exe: 0xC0000005: Access violation writing location 0x00000000DDDDDDDD.

The problem described corresponds to a certain setup (compiler, OS etc.).

Now your last comment refers to a build error which I don't understand where it belongs (in the SDK build process or in your code build?). Either case it is not related to this thread in my understanding.

In the case I am wrong, please define your problem as the first post in order to have a solid ground about your issue.

shivanshtech commented 3 years ago

@ThanasisPap here are the things i did-

  1. aws-sdk-cpp build with vs 2017 win64.
  2. copied the debug dlls and release dlls in the testing app debug and release folder of my project in vs 2013 professional.
  3. showing the error "Exception Thrown at aws-cpp-sdk-core.dll on x64 msvc build "
  4. it is though working fine with vs 2017 but i need to work it with vs 2013 as my entire project is in vs 2013.
ThanasisPap commented 3 years ago

@shivanshtech
What compiler you are using in Visual Studio 2013? Also about step 2, did you copy the include folders as mentioned before?