aws / aws/aws-sdk-cpp

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

Open
#2,502 3 comments 0 reactions 0 assignees View on GitHub
bug Cmake p3
Dominant language
C++
Stars
2.2k
Forks
1.2k
Avg merge
3d 14h
Merged PRs (30d)
12

Description

### 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:
```cpp
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:
```bash
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
```
3. 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:
```bash
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: https://github.com/aws/aws-sdk-cpp/issues/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.