aws / aws/aws-sdk-cpp

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

Aperta
#2,502 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug Cmake p3
Lingua principale
C++
Stelle
2.2k
Fork
1.2k
Merge medio
4g 11h
PR unite (30g)
13

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo la build statica Windows con il comando CMake fornito e l'applicazione Hello S3 in Visual Studio 2019. Esamina come la build AWS configura Curl per il linking statico e verifica il risultato ricompilando l'applicazione senza simboli Curl non risolti; i flag CURL_STATICLIB proposti nell'issue forniscono un confronto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, cmake, cpp
Ambito
build-system, devtools, operating-systems
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.