Linking against SDK fails when CRT is built as shared object
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 1.2k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 12
Description
### Describe the bug
When the CRT library is built as a shared object, applications fail to link against the SDK using pkgconfig because the `aws-cpp-sdk-core.pc` file doesn't include a dependency on the CRT shared libs (I think it should either be in the `Libs:` or `Requires:` entries).
This doesn't happen by default when the CRT is built as submodules within the main build (i.e. with `BUILD_DEPS=ON`) because in that case, CRT is linked statically into the `aws-cpp-sdk-core.so` file.
### Expected Behavior
Applications and libraries can build against the SDK when CRT is linked dynamically.
### Current Behavior
The link stage of building a [gstreamer library](https://github.com/amzn/amazon-s3-gst-plugin) that uses the SDK fails due to the error `undefined reference to 'Aws::Crt::ApiAllocator()'`. Full build logs:
```bash
root@localhost:/src/amazon-s3-gst-plugin# ninja -C build
ninja: Entering directory `build'
[5/12] Compiling C++ object src/libgstawscredentials-1.0.so.p/gstawscredentials.cpp.o
../src/gstawscredentials.cpp: In function ‘void _do_init(GType)’:
../src/gstawscredentials.cpp:223:3: warning: missing initializer for member ‘_GstValueTable::_gst_reserved’ [-Wmissing-field-initializers]
223 | };
| ^
[6/12] Linking target src/libgstawscredentials-1.0.so
FAILED: src/libgstawscredentials-1.0.so
c++ -o src/libgstawscredentials-1.0.so src/libgstawscredentials-1.0.so.p/gstawscredentials.cpp.o -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libgstawscredentials-1.0.so -Wl,-rpath,/usr/local/lib -Wl,-rpath-link,/usr/local/lib /usr/local/lib/libaws-cpp-sdk-sts.so /usr/local/lib/libaws-cpp-sdk-core.so /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so /usr/lib/x86_64-linux-gnu/libgobject-2.0.so /usr/lib/x86_64-linux-gnu/libglib-2.0.so -Wl,--end-group
/usr/bin/ld: src/libgstawscredentials-1.0.so.p/gstawscredentials.cpp.o: in function `Aws::Endpoint::DefaultEndpointProvider, Aws::Endpoint::BuiltInParameters, Aws::Endpoint::ClientContextParameters>::DefaultEndpointProvider(char const*, unsigned long)':
/usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:53: undefined reference to `Aws::Crt::ApiAllocator()'
/usr/bin/ld: /usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:54: undefined reference to `Aws::Crt::ByteCursorFromArray(unsigned char const*, unsigned long)'
/usr/bin/ld: /usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:53: undefined reference to `Aws::Crt::ByteCursorFromArray(unsigned char const*, unsigned long)'
/usr/bin/ld: /usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:53: undefined reference to `Aws::Crt::Endpoints::RuleEngine::RuleEngine(aws_byte_cursor const&, aws_byte_cursor const&, aws_allocator*)'
/usr/bin/ld: src/libgstawscredentials-1.0.so.p/gstawscredentials.cpp.o: in function `Aws::Endpoint::DefaultEndpointProvider, Aws::Endpoint::BuiltInParameters, Aws::Endpoint::ClientContextParameters>::~DefaultEndpointProvider()':
/usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:63: undefined reference to `Aws::Crt::Endpoints::RuleEngine::~RuleEngine()'
/usr/bin/ld: /usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:63: undefined reference to `Aws::Crt::Endpoints::RuleEngine::~RuleEngine()'
/usr/bin/ld: /usr/local/include/aws/core/endpoint/DefaultEndpointProvider.h:63: undefined reference to `Aws::Crt::Endpoints::RuleEngine::~RuleEngine()'
collect2: error: ld returned 1 exit status
[7/12] Compiling C++ object src/libmultipartuploader.a.p/gsts3multipartuploader.cpp.o
ninja: build stopped: subcommand failed.
```
### Reproduction Steps
The build failure can be reproduced using the below Dockerfile.
Create a file named `Dockerfile` containing:
```
FROM public.ecr.aws/lts/ubuntu:22.04
RUN apt-get update && apt-get -y -qq install \
git curl cmake libcurl4-openssl-dev openssl libssl-dev \
gstreamer1.0-plugins-base libgstreamer1.0-dev \
python3-pip python3-setuptools \
&& pip3 install \
meson ninja
RUN mkdir /crt
WORKDIR /crt
RUN git clone --depth 1 --recurse-submodules https://github.com/awslabs/aws-crt-cpp.git
RUN cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local/lib -DBUILD_SHARED_LIBS=ON aws-crt-cpp
RUN make -j 4 && make install
RUN mkdir /sdk
WORKDIR /sdk
RUN git clone --depth 1 https://github.com/aws/aws-sdk-cpp.git
RUN cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local/lib -DBUILD_DEPS=OFF -DENABLE_TESTING=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_ONLY="s3;sts" aws-sdk-cpp
RUN make -j 4 && make install
RUN mkdir /src
WORKDIR /src
RUN git clone https://github.com/amzn/amazon-s3-gst-plugin.git
WORKDIR /src/amazon-s3-gst-plugin
RUN meson build
ENTRYPOINT /bin/bash
```
Then run these commands to reproduce the build:
```
$ docker build -t aws-sdk-cpp-build-issue:latest .
$ docker run -it aws-sdk-cpp-build-issue:latest
(inside container) ninja -C build
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### AWS CPP SDK version used
v1.10.30 (but also happens with latest)
### Compiler and Version used
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
### Operating System and version
Ubuntu 22.04
Contributor guide
Assessment
This issue has not been assessed yet.