阿里云OSS C++ SDK CURLINFO_CONTENT_LENGTH_DOWNLOAD’ is deprecated

编译阿里云OSS C++ SDK 出现 错误:‘CURLINFO_CONTENT_LENGTH_DOWNLOAD’ is deprecated:…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[25/204] Building CXX object sdk/CMakeFiles/cpp-sdk.dir/src/http/CurlHttpClient.cc.o
FAILED: sdk/CMakeFiles/cpp-sdk.dir/src/http/CurlHttpClient.cc.o
/usr/bin/c++ -DPLATFORM_LINUX -I/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/include -I/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/include/alibabacloud/oss -I/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/external -std=c++11 -fno-exceptions -fPIC -Wall -Werror -pedantic -Wextra -MD -MT sdk/CMakeFiles/cpp-sdk.dir/src/http/CurlHttpClient.cc.o -MF sdk/CMakeFiles/cpp-sdk.dir/src/http/CurlHttpClient.cc.o.d -o sdk/CMakeFiles/cpp-sdk.dir/src/http/CurlHttpClient.cc.o -c '/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc'
In file included from /home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc:18:
/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc: In function ‘size_t AlibabaCloud::OSS::recvHeaders(char*, size_t, size_t, void*)’:
/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc:325:48: 错误:‘CURLINFO_CONTENT_LENGTH_DOWNLOAD’ is deprecated: since 7.55.0. Use CURLINFO_CONTENT_LENGTH_DOWNLOAD_T [-Werror=deprecated-declarations]
325 | curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &dval);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/curl/curl.h:2883:3: 附注:在此声明
2883 | CURLINFO_CONTENT_LENGTH_DOWNLOAD
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc: In member function ‘virtual std::shared_ptr<AlibabaCloud::OSS::HttpResponse> AlibabaCloud::OSS::CurlHttpClient::makeRequest(const std::shared_ptr<AlibabaCloud::OSS::HttpRequest>&)’:
/home/cvrain/下载/aliyun-oss-cpp-sdk/sdk/src/http/CurlHttpClient.cc:550:28: 错误:‘CURLOPT_PROGRESSFUNCTION’ is deprecated: since 7.32.0. Use CURLOPT_XFERINFOFUNCTION [-Werror=deprecated-declarations]
550 | curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
| ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/curl/curl.h:1299:3: 附注:在此声明
1299 | CURLOPTDEPRECATED(CURLOPT_PROGRESSFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 56,
| ^~~~~~~~~~~~~~~~~
cc1plus:所有的警告都被当作是错误
[38/204] Building CXX object sdk/CMakeFiles/cpp-sdk.dir/src/encryption/OssEncryptionClient.cc.o
ninja: build stopped: subcommand failed.

这个问题是因为curl在7.55 废弃了CURLINFO_CONTENT_LENGTH_DOWNLOAD
在7.32废弃了CURLOPT_PROGRESSFUNCTION
存在两种修复方式,第二种是修改源代码使用现在支持的方式,这个比较麻烦。第一种方式是添加flags使其忽略此警告。
CMakeLists.txt中添加如下代码:

1
2
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

完整的CMakeLists.txt

#
# Copyright 2009-2017 Alibaba Cloud All rights reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cmake_minimum_required(VERSION 3.1)

cmake_policy(SET CMP0048 NEW)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")


#Project setting
file(STRINGS "VERSION" version)
project(alibabacloud-oss-cpp-sdk VERSION ${version})
message(STATUS "Project version: ${PROJECT_VERSION}")
set(SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
set(TARGET_OUTPUT_NAME_PREFIX "alibabacloud-oss-" CACHE STRING "The target's output name prefix")

#Options
option(BUILD_SHARED_LIBS  "Enable shared library" OFF)
option(BUILD_SAMPLE "Build sample" ON)
option(BUILD_TESTS "Build unit and perfermence tests" OFF)
option(ENABLE_COVERAGE "Flag to enable/disable building code with -fprofile-arcs and -ftest-coverage. Gcc only" OFF)
option(ENABLE_RTTI "Flag to enable/disable building code with RTTI information" ON)


#Platform
if (CMAKE_CROSSCOMPILING)
    if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
        set(PLATFORM_ANDROID 1)
        set(TARGET_OS "ANDROID")
    else()
        message(FATAL_ERROR "Do not support target platform")
    endif()
else()
    if(CMAKE_HOST_APPLE)
        set(PLATFORM_APPLE 1)
        set(TARGET_OS "APPLE")
    elseif(CMAKE_HOST_UNIX)
        set(PLATFORM_LINUX 1)
        set(TARGET_OS "LINUX")
    elseif(CMAKE_HOST_WIN32)
        set(PLATFORM_WINDOWS 1)
        set(TARGET_OS "WINDOWS")
    else()
        message(FATAL_ERROR "Do not support unknown host OS")
    endif()
endif()

message(STATUS "TARGET_OS: ${TARGET_OS}")

add_definitions(-DPLATFORM_${TARGET_OS})

#Find dependency Library, curl, openssl
if (${TARGET_OS} STREQUAL "WINDOWS")
    set(WLIB_TARGET "Win32")
    if (CMAKE_CL_64)
    set(WLIB_TARGET "x64")
    endif()
    set(CRYPTO_LIBS 
        ${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/ssleay32.lib 
        ${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libeay32.lib)
    set(CRYPTO_INCLUDE_DIRS 
        ${CMAKE_SOURCE_DIR}/third_party/include) 

    set(CLIENT_LIBS 
        ${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libcurl.lib) 
    set(CLIENT_INCLUDE_DIRS 
        ${CMAKE_SOURCE_DIR}/third_party/include) 
else()
    include(FindCURL)
    include(FindOpenSSL)

    if(NOT CURL_FOUND)
        message(FATAL_ERROR "Could not find curl")
    endif()

    if(NOT OPENSSL_FOUND)
        message(FATAL_ERROR "Could not find openssl")
    endif()

    set(CRYPTO_LIBS ${OPENSSL_LIBRARIES})
    set(CRYPTO_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) 
    set(CRYPTO_LIBS_ABSTRACT_NAME crypto ssl)

    set(CLIENT_LIBS ${CURL_LIBRARIES})
    set(CLIENT_INCLUDE_DIRS ${CURL_INCLUDE_DIRS}) 
    set(CLIENT_LIBS_ABSTRACT_NAME curl)
endif()

#Compiler flags
list(APPEND SDK_COMPILER_FLAGS "-std=c++11")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    list(APPEND SDK_COMPILER_FLAGS "/MP")
    if (NOT ENABLE_RTTI)
    list(APPEND SDK_COMPILER_FLAGS "/GR-")
    endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC")
    if (NOT ENABLE_RTTI)
    list(APPEND SDK_COMPILER_FLAGS "-fno-rtti")
    endif()
    
    list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
else()
    list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC")
    if (NOT ENABLE_RTTI)
    list(APPEND SDK_COMPILER_FLAGS "-fno-rtti")
    endif()
    
    list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
    
    if (ENABLE_COVERAGE)
    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
    SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
    SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
    endif()
endif()


if (BUILD_SHARED_LIBS)
    set(STATIC_LIB_SUFFIX "-static")
else()
    set(STATIC_LIB_SUFFIX "")
endif()

include(ExternalProject)
include(GNUInstallDirs)

add_subdirectory(sdk)

if(BUILD_SAMPLE)
    add_subdirectory(sample)
endif()

if(BUILD_TESTS)
    add_subdirectory(test)
    add_subdirectory(ptest)
endif()

```s

阿里云OSS C++ SDK CURLINFO_CONTENT_LENGTH_DOWNLOAD’ is deprecated
http://cvrain.cloudvl.cn/2023/12/04/Cpp/cpp-oss-compile/
作者
ClaudeRainer
发布于
2023年12月4日
许可协议