| 类别 | 依赖 | 获取方式 |
|---|---|---|
| 系统(需手动/脚本安装) | OpenSSL、libcurl、libevent、nlohmann_json | scripts/install_deps.sh 或系统包管理器 |
| CMake 自动拉取 | http_parser、Google Test 等 | 构建时 third_party/third_party.cmake(系统包优先,否则 FetchContent) |
| 测试专用 | Google Test、gcovr | 启用 --with-tests / run_ut.sh 时按需安装 |
scripts/ 下脚本均为 Bash(#!/usr/bin/env bash,含 set -o pipefail 等语法)。请使用 bash scripts/... 调用,勿用 sh;在 dash 等环境下 sh scripts/build.sh 会报错(如 set: Illegal option -o pipefail)。
| 脚本 | 解释器 | 用途 |
|---|---|---|
scripts/install_deps.sh |
bash | 安装 OpenSSL、libcurl、libevent 等系统开发包 |
scripts/build.sh |
bash | 配置与编译 SDK、示例、单元测试 |
scripts/run_ut.sh |
bash | 运行 CTest 并生成测试/覆盖率报告 |
scripts/run_example.sh |
bash | 示例冒烟测试 |
| 依赖 | 最低版本 | 用途 |
|---|---|---|
| C++ 编译器 | C++17 | 语言标准 |
| CMake | 3.15 | 构建系统 |
| OpenSSL | 1.1.1 | TLS、加密 |
| libcurl | 7.x+ | HTTP Client 传输 |
| nlohmann_json | 3.11.2 | JSON 序列化 |
| libevent | 2.1.12 | 事件循环(Server I/O) |
| http_parser | 2.9.4 | HTTP 解析 |
| GNU coreutils | — | 仅 macOS:run_example.sh 超时保护(提供 gtimeout;Linux 自带 timeout) |
cd A2A/cpp-sdk
bash scripts/install_deps.sh脚本会检测 Ubuntu/Debian、RHEL/CentOS/Fedora/EulerOS、Arch 等,并安装 libcurl、OpenSSL、libevent、nlohmann_json 等开发包。
sudo apt-get update
sudo apt-get install -y \
build-essential cmake \
libssl-dev \
libcurl4-openssl-dev \
libevent-dev \
nlohmann-json3-devsudo yum install -y \
gcc-c++ cmake \
openssl-devel \
libcurl-devel \
libevent-develsudo pacman -S --needed base-devel cmake openssl curl libevent nlohmann-jsonbrew install cmake pkgconf openssl@3 curl libevent nlohmann-json coreutilsmacOS 上 OpenSSL/curl 为 keg-only,CMake 会自动从 Homebrew 前缀查找它们;也可用
bash scripts/install_deps.sh 自动安装。
macOS 没有 GNU timeout,scripts/run_example.sh 的冒烟测试依赖 coreutils 提供的
gtimeout 做超时保护(找不到时会直接报错退出,不会静默取消超时)。
conda/Anaconda 环境注意:若当前 shell 激活了 conda(
CONDA_PREFIX非空),其自带的 OpenSSL/curl/libevent/nlohmann_json/GTest 等可能被 CMake 抢先选中,导致链接错误或 undefined symbols。构建前请conda deactivate(含 base),并删除build/后重新配置 (CMake 会把已找到的路径缓存进build/CMakeCache.txt,不删缓存不生效)。
# OpenSSL
openssl version
# libcurl
curl-config --version
# CMake
cmake --version
# GNU timeout(macOS 为 gtimeout,来自 coreutils)
timeout --version 2>/dev/null || gtimeout --version- 其余第三方库在首次
cmake配置时由third_party/third_party.cmake处理,一般无需单独安装。 - 若需离线构建,可预先安装上述系统包,并配置 CMake 使用系统提供的 json/libevent 等(见
A2A_USE_SYSTEM_*选项)。 - 从其他机器同步工程时,建议清理
third_party/*-subbuild后再配置,避免 CMakeCache 路径不一致。