Skip to content

Application build error with AWS SDK/Curl as static libraries on Windows #2502

Open
@Shempp

Description

@Shempp

Describe the bug

An application that uses the static libraries of AWS and Curl is built with errors on Windows.

Expected Behavior

An application that uses the static libraries of AWS and Curl is built without errors on Windows.

Current Behavior

If you try to use the static versions of AWS/Curl we get numerous errors at the linking stage, for example:

1>aws-cpp-sdk-core.lib(CurlHttpClient.obj) : error LNK2019: unresolved external symbol __imp__curl_global_init in function "public: static void __cdecl Aws::Http::CurlHttpClient::InitGlobalState(void)" (?InitGlobalState@CurlHttpClient@Http@Aws@@SAXXZ).

Reproduction Steps

  1. Build Curl as static library
  2. Build AWS as static library
    CMake command:
cmake -A Win32 -DCMAKE_INSTALL_PREFIX="C:/aws-sdk-cpp" -DBUILD_ONLY="s3" -DFORCE_CURL=ON -DCURL_INCLUDE_DIR="C:/curl/include" -DCURL_LIBRARY="C:/curl/lib/libcurl.lib" -DBUILD_SHARED_LIBS=OFF -DCPP_STANDARD=14 -DENABLE_TESTING=OFF -DTARGET_ARCH=WINDOWS -B build
  1. Try to build "Hello S3" app (https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/build-cmake.html) in Visual Studio 2019 (linking and include files configured)

Possible Solution

The AWS documentation (Developer Guide, Getting Started -> Getting SDK from source -> Build on Windows) mentions an example of using Curl only as a dynamic library on Windows but it can also be used in the static version with some clarifications (for example someone uses all dependencies as static libraries).

To fix it you need to notify Сurl about its use in the static version: define the CURL_STATICLIB preprocessor directive when building AWS libraries (https://github.com/curl/curl/tree/master/winbuild#building-your-own-application-with-a-static-libcurl). I did it by setting flags CMAKE_C_FLAGS_INIT and CMAKE_CXX_FLAGS_INIT when executing the CMake command like this:

cmake -A Win32 -DCMAKE_INSTALL_PREFIX="C:/aws-sdk-cpp" -DBUILD_ONLY="s3" -DFORCE_CURL=ON -DCURL_INCLUDE_DIR="C:/curl/include" -DCURL_LIBRARY="C:/curl/lib/libcurl.lib" -DBUILD_SHARED_LIBS=OFF -DCPP_STANDARD=14 -DENABLE_TESTING=OFF -DTARGET_ARCH=WINDOWS -DCMAKE_C_FLAGS_INIT="/DCURL_STATICLIB" -DCMAKE_CXX_FLAGS_INIT="/DCURL_STATICLIB" -B build

Previously, it was enough to define a CURL_STATICLIB preprocessor directive at the application level - this does not work now.

Additional Information/Context

Curl version used
8.1.0

Also a similar topic has already been raised but for Linux: #1270

AWS CPP SDK version used

1.11.82

Compiler and Version used

MSVC 19.29.30148

Operating System and version

Windows 10 22H2 10.0.19045.2846

Metadata

Metadata

Assignees

No one assigned

    Labels

    CmakeCmake related submissionsbugThis issue is a bug.p3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions