使用 conan、cmake 的 C++ 与 CURL、OpenSSL 和 AWS SDK S3 的链接问题

问题描述 投票:0回答:1

我在同时链接两个库(CURL、OpenSSL 和 AWS SDK S3)时遇到问题。但问题是我需要用 conan 2.0 管理另一个库。

我尽可能缩小了 CMakeLists.txt 和示例源代码。

[环境]

  1. 两个 Conan 依赖项,
    openssl/3.1.4
    libcurl/8.4.0
  2. 我已经通过阅读官方教程在我的计算机上手动安装了aws-sdk-cpp-s3。 (当然,我做到了
    make install
    。)

项目结构

$ 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);
}

我是如何构建的?

$ 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

[问题]

$ ./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)

我可以看到上面写着

The libcrypto major version number seen at compile-time is different from the major version number seen at run-time

我为解决这个问题做了什么

我以为正在使用

libcrypto
的图书馆是两个。 CURL 和 OpenSSL。因此,我删除了
CURL::libcurl
target_link_libraries
上的
CMakeLists.txt
。它有效。

更改后就可以了。

target_link_libraries(
    ${PROJECT_NAME}
    # CURL::libcurl
    OpenSSL::Crypto
    ${AWSSDK_LINK_LIBRARIES}
)
$ ./AWSS3Test
SUCCESS!

但是,我需要

CURL
库来实现另一个功能。我该如何解决这个问题?

curl cmake openssl libcrypto aws-sdk-cpp
1个回答
0
投票

我有一个与使用 cmake 进行 openssl 链接相关的问题。 我可以使用 cmake 安装它,而不是使用 /usr/local/ssl 中的 pre=installed openssl 。有没有办法使用官方链接中的 CMakeLists.txt 文件构建 openssl 源https://www.openssl.org/source/openssl-3.0.12.tar.gz

© www.soinside.com 2019 - 2024. All rights reserved.