Building Pulsar C++ client

Supported platforms

The Pulsar C++ client has been successfully tested on MacOS and Linux.

System requirements

You need to have the following installed to use the C++ client:

Compilation

There are separate compilation instructions for MacOS and Linux. For both systems, start by cloning the Pulsar repository:

  1. $ git clone https://github.com/apache/pulsar

Linux

First, install all of the necessary dependencies:

  1. $ apt-get install cmake libssl-dev libcurl4-openssl-dev liblog4cxx-dev \
  2. libprotobuf-dev protobuf-compiler libboost-all-dev google-mock libgtest-dev libjsoncpp-dev

Then compile and install Google Test:

  1. # libgtest-dev version is 1.18.0 or above
  2. $ cd /usr/src/googletest
  3. $ sudo cmake .
  4. $ sudo make
  5. $ sudo cp ./googlemock/libgmock.a ./googlemock/gtest/libgtest.a /usr/lib/
  6. # less than 1.18.0
  7. $ cd /usr/src/gtest
  8. $ sudo cmake .
  9. $ sudo make
  10. $ sudo cp libgtest.a /usr/lib
  11. $ cd /usr/src/gmock
  12. $ sudo cmake .
  13. $ sudo make
  14. $ sudo cp libgmock.a /usr/lib

Finally, compile the Pulsar client library for C++ inside the Pulsar repo:

  1. $ cd pulsar-client-cpp
  2. $ cmake .
  3. $ make

The resulting files, libpulsar.so and libpulsar.a, will be placed in the lib folder of the repo while two tools, perfProducer and perfConsumer, will be placed in the perf directory.

MacOS

First, install all of the necessary dependencies:

  1. # OpenSSL installation
  2. $ brew install openssl
  3. $ export OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include/
  4. $ export OPENSSL_ROOT_DIR=/usr/local/opt/openssl/
  5. # Protocol Buffers installation
  6. $ brew tap homebrew/versions
  7. $ brew install protobuf260
  8. $ brew install boost
  9. $ brew install log4cxx
  10. # Google Test installation
  11. $ git clone https://github.com/google/googletest.git
  12. $ cd googletest
  13. $ cmake .
  14. $ make install

Then compile the Pulsar client library in the repo that you cloned:

  1. $ cd pulsar-client-cpp
  2. $ cmake .
  3. $ make