本文由簡體中文內容自動轉碼而成。阿里雲不保證此自動轉碼的準確性、完整性及時效性。本文内容請以簡體中文版本為準。

C++ SDK

更新時間:2024-06-29 22:02

要在 Linux 平台進行編譯, 您必須安裝依賴的外部庫檔案 libcurl、libopenssl、libuuid、libjsoncpp。

  • 安裝支援 C++ 11 或更高版本的編譯器:

    • Windows: Visual Studio 2015 或以上版本

    • Linux: GCC 4.9 或以上版本

  • 安裝 CMake 3.0 或以上版本

  • 建議 4G 或以上記憶體

(1) 從 GitHub 下載或 Git 複製 aliyun-openapi-cpp-sdk

  • 直接下載 https://github.com/aliyun/aliyun-openapi-cpp-sdk/archive/master.zip

  • 使用 Git 命令擷取

git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git

(2) 建立產生必要的構建檔案

cd aliyun-openapi-cpp-sdk
mkdir sdk_build

機器翻譯 C++ SDK 使用主要檔案結構如下:

- /aliyun-openapi-cpp-sdk
--- /alimt
--- /core
--- /sdk_build
--- easyinstall.sh
--- CMakeLists.txt

(3) CMakeLists.txt使用如下檔案替換

cmake_minimum_required(VERSION 3.1)

cmake_policy(SET CMP0048 NEW)

file(STRINGS "VERSION" version)

project(alibabacloud-sdk VERSION ${version})

message(STATUS "Project version: ${PROJECT_VERSION}")

set(TARGET_OUTPUT_NAME_PREFIX "alibabacloud-sdk-" CACHE STRING "The target's output name prefix")
option(BUILD_SHARED_LIBS  "Enable shared library" ON)
option(BUILD_UNIT_TESTS "Enable unit tests" OFF)
option(BUILD_FUNCTION_TESTS "Enable function test" OFF)

set(LIB_TYPE STATIC)
if(BUILD_SHARED_LIBS)
        set(LIB_TYPE SHARED)
        add_definitions(-DALIBABACLOUD_SHARED)
endif()

set_property(GLOBAL
        PROPERTY
        USE_FOLDERS ON)

set(CMAKE_CXX_STANDARD 11)

include(ExternalProject)
include(GNUInstallDirs)

add_subdirectory(3rdparty)
add_subdirectory(core)

if(BUILD_UNIT_TESTS)
        enable_testing()
        add_subdirectory(test/core)
endif()

if(BUILD_FUNCTION_TESTS)
  enable_testing()
  add_subdirectory(test/function_test/cdn)
  add_subdirectory(test/function_test/core)
  add_subdirectory(test/function_test/cs)
  add_subdirectory(test/function_test/ecs)
  add_subdirectory(test/function_test/nlp)
  add_subdirectory(test/function_test/rds)
  add_subdirectory(test/function_test/slb)
  add_subdirectory(test/function_test/vpc)
endif()

add_subdirectory(alimt)

(4)通過 easyinstall.sh一鍵式安裝

cd aliyun-openapi-cpp-sdk
sudo sh easyinstall.sh

Alibaba Cloud SDK for C++ 將被安裝在 /usr.

操作步驟

為快速開始使用機器翻譯 C++ SDK,請按照如下步驟進行。

步驟 1 建立阿里雲帳號

具體方法請參考阿里雲帳號註冊流程

為了更好地使用阿里雲服務,建議儘快完成實名認證,否則部分阿里雲服務將無法使用。

步驟 2 擷取阿里雲存取金鑰

為了使用機器翻譯 C++ SDK,您必須申請阿里雲的存取金鑰

登入阿里雲密鑰管理頁面 。選擇一對用於 SDK 的存取金鑰對。如果沒有,請建立一對新存取金鑰,且保證它處於啟用狀態。 密鑰指的是Access Key ID和Access Key Secret

該金鑰組會在下面的步驟使用,且需要保管好,不能對外泄露。

步驟 3 開始一個 C++ 程式

範例程式碼詳見SDK樣本(C++)

  • 本頁導讀 (0, M)
  • 操作步驟
  • 步驟 1 建立阿里雲帳號
  • 步驟 2 擷取阿里雲存取金鑰
  • 步驟 3 開始一個 C++ 程式
文檔反饋