aws-sdk-cpp icon indicating copy to clipboard operation
aws-sdk-cpp copied to clipboard

CMake error when using SDK built with `-DBUILD_SHARED_LIBS=OFF`

Open kkarbowiak opened this issue 2 years ago • 8 comments

Describe the bug

I am getting a CMake error when trying to use the 1.11 line of the SDK. I did not get this error when using both 1.9 and 1.10.

Expected Behavior

Expected behaviour is no CMake error.

Current Behavior

The error appears during CMake configure step:

CMake Error at CMakeLists.txt:5 (add_executable):
  Target "s3sample" links to target "ZLIB::ZLIB" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

Reproduction Steps

I first stumbled upon the problem on my project that included aws-sdk-cpp, aws-lambda-cpp and several other dependencies, but was also able to reproduce it on the sample program from this Wiki page: https://github.com/aws/aws-sdk-cpp/wiki/Building-the-SDK-from-source-on-EC2

Steps to reproduce:

  1. clone the aws-sdk-cpp repo
git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp.git
cd aws-sdk-cpp
git checkout --recurse-submodules 1.11.138
  1. build and install the SDK
mkdir build-sdk
cd build-sdk
cmake ../aws-sdk-cpp -D BUILD_ONLY=core -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BUILD_SHARED_LIBS=OFF -D CMAKE_INSTALL_PREFIX=~/aws-sdk-1.11.138
make
make install
  1. CMake configure the app
mkdir build
cd build
cmake .. -D CMAKE_BUILD_TYPE=Release -D CMAKE_PREFIX_PATH=~/aws-sdk-1.11.138

Possible Solution

No response

Additional Information/Context

It seems that using static libraries adds linking the ZLIB:ZLIB target, which then cannot be recognised. Please search for ZLIB:ZLIB in the installed lib/cmake/aws-sdk-cpp-core/aws-sdk-cpp-core-targets.cmake file.

AWS CPP SDK version used

1.11.70, 1.11.76, 1.11.138

Compiler and Version used

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Operating System and version

Ubuntu 22.04 running on WSL2

kkarbowiak avatar Aug 22 '23 14:08 kkarbowiak

It seems the problem is introduced in commit e3db71c, as I do not get the above error when using 1.11.33 and get it when using 1.11.34.

kkarbowiak avatar Aug 28 '23 14:08 kkarbowiak

Do you have zlib installed? You can install this with:

sudo apt install zlib1g-dev

jmklix avatar Aug 31 '23 16:08 jmklix

Do you have zlib installed? You can install this with:

sudo apt install zlib1g-dev

Yes, it's installed. But just to confirm:

> sudo apt install zlib1g-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
zlib1g-dev is already the newest version (1:1.2.11.dfsg-2ubuntu9.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

kkarbowiak avatar Aug 31 '23 20:08 kkarbowiak

I am hitting the same issue on Mac OS X with -DBUILD_SHARED_LIBS=OFF. When I build it as a standalone project it builds fine. When I include it as a dependency for another project then I get exactly this error

I'm adding as an external project like so:

ExternalProject_Add(libawscpp-download
    GIT_REPOSITORY    https://github.com/aws/aws-sdk-cpp.git
    GIT_TAG           1.11.157
    LIST_SEPARATOR    "|"
    CMAKE_ARGS       -DBUILD_SHARED_LIBS=OFF
                     -DBUILD_ONLY=kinesis-video-media|kinesis-video-webrtc-storage
    BUILD_ALWAYS      TRUE
    TEST_COMMAND      ""
)

And below is the error:

-- Try finding aws-cpp-sdk-core
-- Found aws-cpp-sdk-core
-- Try finding aws-cpp-sdk-kinesis-video-webrtc-storage
-- Found aws-cpp-sdk-kinesis-video-webrtc-storage
-- Try finding aws-cpp-sdk-kinesis-video-media
-- Found aws-cpp-sdk-kinesis-video-media
-- Configuring done (673.9s)
CMake Error at /usr/local/lib/cmake/aws-cpp-sdk-core/aws-cpp-sdk-core-targets.cmake:61 (set_target_properties):
  The link interface of target "aws-cpp-sdk-core" contains:

    ZLIB::ZLIB

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /usr/local/lib/cmake/aws-cpp-sdk-core/aws-cpp-sdk-core-config.cmake:19 (include)
  /usr/local/lib/cmake/AWSSDK/AWSSDKConfig.cmake:310 (find_package)
  tst/CMakeLists.txt:14 (find_package)


-- Generating done (0.1s)

Some other CMake details:

-- TARGET_ARCH not specified; inferring host OS to be platform compilation target
-- Building AWS libraries as static objects
-- Building project version: 1.11.157
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/local/bin/python3.9 (found version "3.9.16") 
-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libz.tbd (found version "1.2.11")  
--   Zlib library: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libz.tbd
-- Encryption: CommonCrypto
-- Http client: Curl
-- Found CURL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libcurl.tbd (found version "7.79.1")  
--   Curl include directory: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include
--   Curl library: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libcurl.tbd
-- AWS CRT C++ 0.23.0
-- The C compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done

I do not hit this issue though if I clone the project by itself and build it.

hassanctech avatar Sep 06 '23 13:09 hassanctech

Also I can confirm if I simply call:

  find_package(ZLIB REQUIRED)

Right before the CMakeLists.txt which has the ExternalProject_Add it fixes the issue. It would appear there is a bug in the aws sdk CMakeLists.txt that doesn't properly handle the static link case.

hassanctech avatar Sep 06 '23 14:09 hassanctech

I don't see ExternalProject_Add anywhere in the CMakeLists.txt file. Are you referencing adding the above call to the docs here: https://github.com/aws/aws-sdk-cpp/blob/53a6699f24ad6a6603074fdb630d3c1dc235d3c1/docs/CMake_External_Project.md?plain=1#L10-L18

jmklix avatar Sep 07 '23 00:09 jmklix

Exactly yes I'm following that to include as an external project.

hassanctech avatar Sep 07 '23 13:09 hassanctech

Also I can confirm if I simply call:

  find_package(ZLIB REQUIRED)

Right before the CMakeLists.txt which has the ExternalProject_Add it fixes the issue. It would appear there is a bug in the aws sdk CMakeLists.txt that doesn't properly handle the static link case.

It works for me! Thank you.

quaaanLee avatar Jan 06 '24 08:01 quaaanLee

find_package(ZLIB REQUIRED)

This worked for me!

StevePerezUK avatar Aug 21 '25 15:08 StevePerezUK