Skip to content

AWS::InitAPI fails on windows #1692

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

Closed
atitusfwd opened this issue Jun 22, 2021 · 18 comments
Closed

AWS::InitAPI fails on windows #1692

atitusfwd opened this issue Jun 22, 2021 · 18 comments
Assignees
Labels
closed-for-staleness guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@atitusfwd
Copy link

I'm trying to learn to use the AWS C++ SDK, windows platform, building with CMAKE. I have simplified this down to the basic skeleton defined here: https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/basic-use.html

The program source:

`#include <aws/core/Aws.h>

int main()
{
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
Aws::InitAPI(options);
{
printf("Hello CMake.\n");
}
Aws::ShutdownAPI(options);
return 0;
}`

The result is the same even if the options configuration is commented out. When running the executable, there is no output written to std out or std error, The log file is created but is completely empty (zero bytes). The return code from the program is
-1073741819 as obtained from %errorlevel% variable. If the program is run repeatedly, it will (infrequently) produce the following error stack trace to the console:

Fatal error condition occurred in C:\Temp\build\aws-sdk-cpp\crt\aws-crt-cpp\crt\aws-c-io\source\event_loop.c:74: aws_thread_launch(&cleanup_thread, s_event_loop_destroy_async_thread_fn, el_group, &thread_options) == AWS_OP_SUCCESS
Exiting Application
at 0x7FFC390A2530: aws_backtrace_print
at 0x7FFC39093330: aws_fatal_assert
at 0x7FFC37575F10: aws_event_loop_wait_for_stop_completion
at 0x7FFC3909F630: aws_ref_count_release
at 0x7FFC37573D80: aws_server_bootstrap_set_alpn_callback
at 0x7FFC3909F630: aws_ref_count_release
at 0x7FFC37573760: aws_client_bootstrap_release
at 0x7FFC390F73E0: Aws::Crt::Io::ClientBootstrap::~ClientBootstrap
at 0x7FFC115AD5D0: Aws::Utils::Stream::SimpleStreamBuf::xsputn
at 0x7FFC57614180: execute_onexit_table
at 0x7FFC57614180: execute_onexit_table
at 0x7FFC57614180: execute_onexit_table
at 0x7FFC115AD5D0: Aws::Utils::Stream::SimpleStreamBuf::xsputn
at 0x7FFC115AD5D0: Aws::Utils::Stream::SimpleStreamBuf::xsputn
at 0x7FFC596A9900: RtlActivateActivationContextUnsafeFast
at 0x7FFC596EDA50: LdrShutdownProcess
at 0x7FFC596ED980: RtlExitUserProcess
at 0x7FFC57CBE0A0: FatalExit
at 0x7FFC04D439F0: wassert
at 0x7FFC04D439F0: wassert
at 0x7FFC04D440F0: Exit
at 0x7FFC04D3D850: abort
at 0x7FFC04D3C850: terminate
at 0x7FF7DA3C7370: __scrt_unhandled_exception_filter(d:\agent_work\4\s\src\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:96)
at 0x7FFC5723B6A0: UnhandledExceptionFilter
at 0x7FFC59733EC0: memset
at 0x7FFC5971C6E0: _C_specific_handler
at 0x7FFC59732060: _chkstk
at 0x7FFC596E1020: RtlRaiseException
at 0x7FFC596E1020: RtlRaiseException
at 0x7FFC57164B20: RaiseException
at 0x7FFC38E063F0: CxxThrowException
at 0x7FFC119DAC30: std::_Xbad_function_call
at 0x7FFC11590370: Aws::Monitoring::InitMonitoring
at 0x7FFC1151CFC0: Aws::InitAPI
at 0x7FF7DA3C1B40: main(C:\projects\awsencrypt1\awsencrypt1.cpp:12)
at 0x7FF7DA3C5150: invoke_main(d:\agent_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
at 0x7FF7DA3C4F00: __scrt_common_main_seh(d:\agent_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
at 0x7FF7DA3C4EE0: __scrt_common_main(d:\agent_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
at 0x7FF7DA3C5210: mainCRTStartup(d:\agent_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
at 0x7FFC57CB7020: BaseThreadInitThunk
at 0x7FFC596E2630: RtlUserThreadStart

@atitusfwd
Copy link
Author

I would really appreciate any suggestions as to how to determine the cause. Compiler info:
14.29.30037/bin/Hostx64/x64/cl.exe

@crusader-mike
Copy link

Aws::InitAPI calls Aws::Monitoring::InitMonitoring which, apparently, somehow calls empty std::function... You can use debugger to figure out why

@KaibaLopez
Copy link
Contributor

It seems to me like you got a linking issue, which can be due to a lot of things so...
Could you walk me through what steps you took to install the SDK and then how you're linking it to your application.

@KaibaLopez KaibaLopez self-assigned this Jun 22, 2021
@KaibaLopez KaibaLopez added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. labels Jun 22, 2021
@atitusfwd
Copy link
Author

My ultimate goal is to use the encryption sdk specifically. I followed the instructions that are in the readme of the git repo (these are the same steps that are in the aws docs). This repo: https://github.com/aws/aws-encryption-sdk-c/ . I had to make one change: when cloning the repo I had to add the recurse subprojects otherwise it was missing things and the cmake didn't work. I took the defaults and built 64 bit release libraries.

I created a new directory, grabbed the example string.cpp that is included with the encryption sdk, and using cmake with find exports to build it. When it didn't work (stuck in AWS:InitAPI, I made the simpler version to just isolate that and I get the same behavior. Here is the cmakelists that is building both:

cmake_minimum_required (VERSION 3.8)

project ("awsencrypt1")

find_package(aws-encryption-sdk-cpp)
link_directories(/apps/aws-encryption-sdk/lib)

add_compile_definitions(USE_IMPORT_EXPORT)

add_executable (awsencrypt1 "string.cpp")
target_link_libraries(awsencrypt1 PRIVATE AWS::aws-c-common aws-cpp-sdk-kms aws-cpp-sdk-core aws-encryption-sdk aws-encryption-sdk-cpp)
set_target_properties(awsencrypt1 PROPERTIES CXX_STANDARD 11 C_STANDARD 99)

add_executable (awstest1 "awsencrypt1.cpp")
target_link_libraries(awstest1 PRIVATE aws-cpp-sdk-core)
set_target_properties(awstest1 PROPERTIES CXX_STANDARD 11 C_STANDARD 99)

@atitusfwd
Copy link
Author

For arguments to cmake, I'm specifying the following:
-DCMAKE_PREFIX_PATH="C:\apps\aws-encryption-sdk" -DBUILD_SHARED_LIBS=ON

The prefix path has the bin, lib and include folders with the header files, cmake packages, etc. It wants the BUILD_SHARED_LIBS property otherwise the cmake exports won't find everything.

@KaibaLopez
Copy link
Contributor

Ok.. so the building seems fine to me, now I'm curious if it's a weird linking interaction between this sdk and the encryption-sdk (maybe some overwriting happening idk).
I'm not really familiar with the encryption-sdk so I'm not sure what the find_package includes for them....
So on that note could you try changing your CMakeLists to just use the cpp sdk?:

cmake_minimum_required (VERSION 3.8)

project ("awsencrypt1" LANGUAGE CXX)

find_package(AWSSDK REQUIRED COMPONENTS kms)
add_executable (awsencrypt1 "string.cpp")
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})
target_compile_options(${PROJECT_NAME} PRIVATE "-Wall")

Also, version 1.9 might have broken their sample, so you might also want to try using version 1.8 of this sdk when cloning, see if that works for you?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 23, 2021
@atitusfwd
Copy link
Author

I tried to build this with the cmakelists you specified. Cmake went OK

1> CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\windows\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\projects\awsencrypt1\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe" -DCMAKE_PREFIX_PATH="C:\apps\aws-encryption-sdk" -DBUILD_SHARED_LIBS=ON -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\projects\awsencrypt1" 2>&1"
1> Working directory: C:\projects\awsencrypt1\out\build\x64-Debug
1> [CMake] -- Found AWS SDK for C++, Version: 1.9.39, Install Root:C:/apps/aws-encryption-sdk, Platform Prefix:, Platform Dependent Libraries: Userenv;version;ws2_32;Bcrypt;Wininet;winhttp
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/projects/awsencrypt1/out/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

But the build failed; it could not find the header:

[1/2] Building CXX object CMakeFiles\awstest1.dir\awsencrypt1.cpp.obj
FAILED: CMakeFiles/awstest1.dir/awsencrypt1.cpp.obj
C:\PROGRA2\MICROS2\2019\COMMUN1\VC\Tools\MSVC\14291.300\bin\Hostx64\x64\cl.exe /nologo /TP -DUSE_IMPORT_EXPORT /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -Wall /showIncludes /FoCMakeFiles\awstest1.dir\awsencrypt1.cpp.obj /FdCMakeFiles\awstest1.dir\ /FS -c ......\awsencrypt1.cpp
C:\projects\awsencrypt1\awsencrypt1.cpp(4): fatal error C1083: Cannot open include file: 'aws/core/Aws.h': No such file or directory
ninja: build stopped: subcommand failed.

@atitusfwd
Copy link
Author

I know I can manually specify the header location, but its supposed to get that automatically from the package, correct?

@KaibaLopez
Copy link
Contributor

Ok I think I know what is going on, couple of things I'd like you to try:

  1. Try adding -DCMAKE_INSTALL_PREFIX="C:\apps\aws-encryption-sdk" to your cmake argument. This should work but if it didn't, tell me the error.

  2. Could you try using the default locations? Just remove -DCMAKE_PREFIX_PATH="C:\apps\aws-encryption-sdk" and -DCMAKE_INSTALL_PREFIX="C:\apps\aws-encryption-sdk". This should install in C:\Program Files (x86)\aws-cpp-sdk-all and cmake should be able to link with not extra instructions... I just want to make sure that there isn't something weird about your environment.

@KaibaLopez KaibaLopez added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 23, 2021
@atitusfwd
Copy link
Author

I tried doing item number 1 first, The cmake worked, same as before. The build still failed. Same error.

[1/2] Building CXX object CMakeFiles\awstest1.dir\awsencrypt1.cpp.obj
FAILED: CMakeFiles/awstest1.dir/awsencrypt1.cpp.obj
C:\PROGRA2\MICROS2\2019\COMMUN1\VC\Tools\MSVC\14291.300\bin\Hostx64\x64\cl.exe /nologo /TP -DUSE_IMPORT_EXPORT /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -Wall /showIncludes /FoCMakeFiles\awstest1.dir\awsencrypt1.cpp.obj /FdCMakeFiles\awstest1.dir\ /FS -c ......\awsencrypt1.cpp
C:\projects\awsencrypt1\awsencrypt1.cpp(4): fatal error C1083: Cannot open include file: 'aws/core/Aws.h': No such file or directory
ninja: build stopped: subcommand failed

@atitusfwd
Copy link
Author

For option #2 -- If I remove these options then find_package will fail. I could physically move the sdk files to that path under program files but .. I'm not sure how cmake is going to know to translate AWSSDK into that path ...

@KaibaLopez
Copy link
Contributor

That is weird, I am not seeing that but it might be a problem of me already having stuff installed/defined on my computer... hopeful thinking on my part here but did you clear up your cmake cache before adding the argument?

Do you mean you tried 2. and failed or are you asking how cmake understands AWSSDK as a path? Because if it's the second, AWSSDK is a variable defined when building the SDK. It should be able to find it on default cmake...
like in theory, building the SDK should be as simple as:

cmake -S . -B build -DBUILD_ONLY="kms" -DBUILD_SHARED_LIBS=ON -DENABLE_TESTING=OFF
MSBuild.exe build/ALL_BUILD.vcxproj
MSBuild.exe build/INSTALL.vcxproj

and then you should be able to link your app, granted windows makes things more complicated by requiring you to have the dlls with the executable, but yea the building should be simple enough. I'm still kind of lost on what's going on on your side....

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 24, 2021
@KaibaLopez KaibaLopez added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 24, 2021
@atitusfwd
Copy link
Author

OK, so decided to try one of the earlier suggestions which was to use the 1.8 version. Instead of cloning the repo and doing a full build I decided to install it via vcpkg instead. This seemed to have better results. Using CMakeLists like this:

cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 11)

project (awsencrypt2 LANGUAGES CXX)
add_executable (awsencrypt2 "awsencrypt2.cpp" )
find_package(AWSSDK REQUIRED COMPONENTS core)
target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES})

I was able to build the program and now Aws::InitAPI runs correctly. The only option I had to pass into cmake was the toolchain file for vcpkg: C:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake

Unfortunately this doesn't exactly tell us what went wrong with the newer version. Vcpkg doesn't have the 1.9 yet, newest is 1.8. If I am able to, I'll try to start over and rebuild the 1.9 again with debug enabled and see if I can track it down. But first I have to get the encryption sdk working, since this is what I really need.

I'm going to create a post over there in the github issue list for the encryption sdk, because I now cannot get that to build using the vcpkg 1.8 version -- it complains that AwsSharedLibSetup include cannot be found even though its there. Sigh.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 25, 2021
@KaibaLopez
Copy link
Contributor

yea I haven't had the time to update the vcpkg for 1.9 (mainly because 1.9 has been problematic to say the least), but yea I am hoping to get that done once all these weird issues stop happening.

Thanks for trying to figure it out with me though, I'll keep looking for a way to reproduce this.

@atitusfwd
Copy link
Author

Assuming that I want to build 1.8 version, how would I go about doing that? The github repo has submodules and I am unsure exactly how this works. If I clone the repo at the 1.8 release, and specify recurse-submodules, will it automatically get the submodules at their "equivalent" release?

@KaibaLopez
Copy link
Contributor

1.8 does not use submodules so there's no need for the recurse-submodules, it will automatically clone and build the dependencies as part of the cmake command.

@KaibaLopez KaibaLopez added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jun 29, 2021
@github-actions
Copy link

github-actions bot commented Jul 3, 2021

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 3, 2021
@github-actions github-actions bot closed this as completed Jul 7, 2021
@im1ex
Copy link

im1ex commented Sep 15, 2022

Had similar issue trying to create sample project with Visual Studio on Windows from scratch with vcpkg AWS SDK.

Didn't use vcpkg integrate install and added all necessary include/lib directories/files by hands into .vcxproj file.

Fixed by using debug files for debug configuration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

4 participants