All Products
Search
Document Center

ApsaraMQ for RocketMQ:Set up the C++ SDK build environment

Last Updated:Mar 10, 2026

The Apache RocketMQ 5.0 SDK for C++ is built on gRPC and must be compiled from source. This guide covers installing dependencies, building gRPC, and compiling the SDK so you can start sending and receiving messages with ApsaraMQ for RocketMQ.

Prerequisites

Install the following tools and libraries before you begin. Each component links to its official installation guide.

ComponentRequired versionPurpose
GCC4.8.5+ (10.2+ recommended)C++11 required. For C++17, use GCC 7+ with -std=c++17 or -std=gnu++17.
CMake3.13+Build system for the SDK and gRPC
OpenSSL1.1.1TLS/SSL library required by gRPC
protobufAny compatible versionProtocol Buffers serialization library

The SDK shares the same compiler compatibility matrix as gRPC.

Step 1: Install gflags

Download, compile, and install gflags 2.2.2:

wget -O gflags-2.2.2.tar.gz https://github.com/gflags/gflags/archive/v2.2.2.tar.gz
tar -xvzf gflags-2.2.2.tar.gz
cd gflags-2.2.2/
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON ..
make
make install
cd

Add the library path so the linker can find gflags at runtime:

cat >> ~/.bashrc << EOF
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib
EOF
source ~/.bashrc

Step 2: Build and install gRPC

Use gRPC 1.46.3. Later versions may not be compatible with the Apache RocketMQ 5.0 SDK for C++.

Set the installation directory and update PATH:

export MY_INSTALL_DIR=$HOME/grpc
mkdir -p $MY_INSTALL_DIR
export PATH="$MY_INSTALL_DIR/bin:$PATH"

Clone and build gRPC:

git clone --recurse-submodules \
    -b v1.46.3 --depth 1 --shallow-submodules \
    https://github.com/grpc/grpc

cd grpc
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON \
    -DgRPC_BUILD_TESTS=OFF \
    -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
      ../..

# Adjust -j based on available CPU cores.
make -j 32
make install
popd
Tip: The -j 32 flag runs 32 parallel compilation jobs. Reduce this number on machines with fewer CPU cores or limited memory. For example, use -j 4 on a 4-core machine.

Step 3: Compile the SDK from source

The SDK supports two build systems: CMake (recommended) and Bazel.

Option A: Build with CMake (recommended)

wget -O rocketmq-clients-cpp-5.0.3.tar.gz https://github.com/apache/rocketmq-clients/archive/refs/tags/cpp-5.0.3.tar.gz
tar -xvzf rocketmq-clients-cpp-5.0.3.tar.gz
cd rocketmq-clients-cpp-5.0.3/cpp
mkdir build && cd build
cmake ..
make

Option B: Build with Bazel

wget -O rocketmq-clients-cpp-5.0.3.tar.gz https://github.com/apache/rocketmq-clients/archive/refs/tags/cpp-5.0.3.tar.gz
tar -xvzf rocketmq-clients-cpp-5.0.3.tar.gz
cd rocketmq-clients-cpp-5.0.3/cpp
bazel build //...

Step 4: Create the required resources

Before you run any sample code, create the following resources in the ApsaraMQ for RocketMQ console:

  • Instance: a RocketMQ service instance

  • Topic: the destination for messages

  • Consumer group: a logical grouping of consumers

For detailed instructions, see Create resources.

Step 5: Run the sample code

After you create the resources, update the parameters in the sample code based on the resource information you obtained in Step 4, then compile and run the examples.