I am having trouble in linking two libraries, CURL, OpenSSL and AWS SDK S3, simultaneously. But the thing is I need to manage another libraries with conan 2.0.
I shrinked CMakeLists.txt and Example source code as much as possible.
[Environment]
- Two Conan Dependencies,
openssl/3.1.4
, andlibcurl/8.4.0
- I already installed aws-sdk-cpp-s3 manually on my computer by reading official tutorial. (And of course, I did
make install
.)
Project structure
$ tree
.
├── build
├── CMakeLists.txt
├── CMakeUserPresets.json
├── conanfile.txt
├── include
├── LICENSE
├── README.md
└── src
└── main.cc
conanfile.txt
[requires]
openssl/3.1.4
libcurl/8.4.0
[tool_requires]
cmake/3.27.0
[generators]
CMakeDeps
CMakeToolchain
CMakeLists.txt
cmake_minimum_required(VERSION 3.27)
project(AWSS3Test VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(AWSSDK REQUIRED COMPONENTS s3)
add_executable(
${PROJECT_NAME}
src/main.cc
)
target_link_libraries(
${PROJECT_NAME}
CURL::libcurl
OpenSSL::Crypto
${AWSSDK_LINK_LIBRARIES}
)
main.cc
#include <iostream>
#include <optional>
#include <openssl/hmac.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
int main() {
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
Aws::InitAPI(options);
int result = 0;
{
Aws::Client::ClientConfiguration clientConfig;
clientConfig.endpointOverride = "XXX.XXX.XXX.XXX:XXXX";
clientConfig.scheme = Aws::Http::Scheme::HTTP;
clientConfig.verifySSL = false;
Aws::Auth::AWSCredentials credentials;
credentials.SetAWSAccessKeyId("____________");
credentials.SetAWSSecretKey("_____________________");
Aws::S3::S3Client client = Aws::S3::S3Client(credentials, clientConfig, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);
auto outcome = client.ListBuckets();
if (outcome.IsSuccess()) {
std::cout << "SUCCESS!" << std::endl;
for (auto&& b : outcome.GetResult().GetBuckets()) {
std::cout << b.GetName() << std::endl;
}
} else {
std::string errorMsg("Failed with error: " + outcome.GetError().GetMessage());
std::cerr << errorMsg << std::endl;
}
}
ShutdownAPI(options);
}
How did I build?
$ conan install . --output-folder=build --build=missing -s compiler.libcxx="libstdc++11"
$ cd build/
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
$ cmake --build . --parallel 9
$ ./AWSS3Test
[Problem]
$ ./AWSS3Test
s2n_init() failed: 402653268 (The libcrypto major version number seen at compile-time is different from the major version number seen at run-time)
Fatal error condition occurred in /root/awsbuild/aws-sdk-cpp/crt/aws-crt-cpp/crt/aws-c-io/source/s2n/s2n_tls_channel_handler.c:203: 0 && "s2n_init() failed"
Exiting Application
################################################################################
Stack trace:
################################################################################
/usr/local/lib64/libaws-cpp-sdk-core.so(aws_backtrace_print+0x98) [0x7f4e1801115d]
/usr/local/lib64/libaws-cpp-sdk-core.so(aws_fatal_assert+0x5b) [0x7f4e17ffb557]
/usr/local/lib64/libaws-cpp-sdk-core.so(aws_tls_init_static_state+0x18c) [0x7f4e17e09e39]
/usr/local/lib64/libaws-cpp-sdk-core.so(aws_io_library_init+0x63) [0x7f4e17dfd378]
/usr/local/lib64/libaws-cpp-sdk-core.so(aws_mqtt_library_init+0x2d) [0x7f4e17d7d62a]
/usr/local/lib64/libaws-cpp-sdk-core.so(_ZN3Aws3Crt9ApiHandleC2EP13aws_allocator+0x58) [0x7f4e17d5aac6]
/usr/local/lib64/libaws-cpp-sdk-core.so(_ZN3Aws3NewINS_3Crt9ApiHandleEJP13aws_allocatorEEEPT_PKcDpOT0_+0x56) [0x7f4e17c50b45]
/usr/local/lib64/libaws-cpp-sdk-core.so(_ZN3Aws13InitializeCrtEv+0x27) [0x7f4e17c5078f]
/usr/local/lib64/libaws-cpp-sdk-core.so(_ZN3Aws7InitAPIERKNS_10SDKOptionsE+0x12e) [0x7f4e17c4c859]
./AWSS3Test() [0x43c650]
/lib64/libc.so.6(__libc_start_main+0xe5) [0x7f4e165f1d85]
./AWSS3Test() [0x43c95e]
Aborted (core dumped)
I can see it said The libcrypto major version number seen at compile-time is different from the major version number seen at run-time
.
What I did for solve this problem
I thought that the library who is using libcrypto
are two. CURL and OpenSSL. So, I remove CURL::libcurl
on target_link_libraries
in CMakeLists.txt
. And It works.
After change, it works.
target_link_libraries(
${PROJECT_NAME}
# CURL::libcurl
OpenSSL::Crypto
${AWSSDK_LINK_LIBRARIES}
)
$ ./AWSS3Test
SUCCESS!
However, I need CURL
library for another function. How can I solve this problem?