読者です 読者をやめる 読者になる 読者になる

Quitada ブログ HAX

Hatena Blog でも Quitada ブログ

Apache Geode Native Client on macOS

Introduction

Apache Geode is the OSS version of Pivotal GemFire (now, Pivotal GemFire may be the commercial version of Apache Geode, though). Yeah, it's one of the implementation of in-memory data grid based on Java. In other words, it's one of the implementation of in-memory key-value store with event processing feaure and so on.

 

Pivotal GemFire Native Client has been the family product of Pivotal GemFire, which provides GemFire client capability for C# and C++ application running on Windows, Linux and Solaris platform. Now, it's open-sourced as Apache Geode Native Client.

 

The most interesting thing of mine for Apache Geode Native Client is supporting macOS additionally. It means that C++ applications running on macOS can access Apache Geode servers natively (I don't have any ideas how many developers want to develop C++ application on macOS rather than Objective-C or Swift applications). Anyhow, I tried to build and install Apache Geode Native Client on macOS. And also, I tried to compile sample C++ application based on Apache Geode Native Client on macOS (actually, I tried on El Capitan. It's OS X rather than macOS). To tell the truth, I met some traps and I introduce my experiences to build and install Apache Geode Native Client on macOS, and run the C++ application on it in this article.

 

Build and install Apache Geode Native Client on macOS 

You can easily build and install Apache Geode Native Client according to BUILDING.md at geode-native repsitory on GitHub. According to BUILDING.md, you need to install CMake, C++11 compiler, Doxygen, Xcode and Xcode command line developer tools. Regarding CMake and Doxygen, you can install them with using Homebrew. Regarding C++11 compiler, it's installed when installing Xcode at the same time, as far as I know.

Anyhow, you need to get the artifacts such as source code from GitHub. I recommend you to clone them with git command rather than download ZIP archive. First, I tried to build and install by downloading ZIP archive. Somehow, I failed to build with unexpected several unknown reasons. Anyhow, you need to install git command line tool.

And also, you actually need to install Apache Geode itself because it's used at the last stage of building Apache Geode Native Client for test purpose and so on. Anyhow, you have to install Apache Geode in your machine. You can build it from source code but you can get a binary for quick install from here

 

The example steps to build and install Apache Geode Native Client is below. I recommend you to specify the install directory of existing Apache Geode and Native Client (i.e., where you want to install) when executing "cmake ../src".

$ cd /path/to/github_local_repository_dir
$ git init
$ git clone https://github.com/apache/geode-native.git
$ cd geode-native
$ git checkout master
$ mkdir build
$ cd build
$ cmake -G "Xcode" -DGEODE_ROOT=/path/to/apache_geode_root_dir -DCMAKE_INSTALL_PREFIX=/path/to/native_client_install_dir ../src
$ cmake --build . -- -j 8
$ cmake --build . --target docs
$ sudo cmake --build . --target install

It slightly takes a long time to finish build Apache Geode Native Client.

By the way, I could successfully build and install Apache Geode Native Client (so far, version 0.0.42) on OS X 10.11 (El Capitan) although BUILDING.md says it's supported for macOS 10.12 (Sierra).

 

Run the simple C++ application with using Apache Geode Native Client on macOS

The main question could be how to set compiler flags and linker flags to build the C++ application with using Apache Geode Native Client on macOS because there are no actual documents mentioning it (2/14/2017, for now).

 

You generally use Clang as the C++ compiler front end on macOS if installing Xcode. The compiler flags and linker flags for Clang are basically compatible with gcc. So the actual those flags for macOS are basically as same as for Linux in the case of Pivotal GemFire. Anyhow, you can basically set up the environment to build your C++ application with using Apache Geode Native Client on macOS according to the following document althogh it' slightly different.

Developing C++ Programs on Linux

The different things are below.

  • Environment variables for dynamic link libraries:
    In the case of GemFire Native Client for Linux, you may use LD_LIBRARY_PATH environment variable. However, you have to use DYLD_LIBRARY_PATH environemnt variable when running your Apache Geode Native Client application on macOS.
  • Linker flag to link the native client C++ cache library to the compiled executable:
    In the case of GemFire Native Client for Linux, you use "-lgfcppcache". However, you set "-lapache-geode" in the case of Apache Geode Native Client.

I prefer to use JetBrains CLion to develop, build and run C++ application as a C++ IDE. Clion uses CMake internally to build applications. My sample CMakeLists.txt file for CLion to build C++ application with using Apache Geode Native Client is below.

cmake_minimum_required(VERSION 3.6)


project(MyFirstNCProjectOnMac)

 

set(CMAKE_CXX_STANDARD 11)

 

set(SOURCE_FILES BasicOperations.cpp BasicOperations.cpp)
add_executable(BasicOperations ${SOURCE_FILES})

 

set(CMAKE_CXX_FLAGS "-D_REENTRANT -m64 -I$ENV{GFCPP}/include")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-rpath,$ENV{GFCPP}/lib -L$ENV{GFCPP}/lib -lapache-geode")

 

message("GFCPP = $ENV{GFCPP}")
message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")

 

Regarding the sample C++ application with using Apache Geode Native Client, you can use quickstart applications which you can find at /path/to/native_client_install_dir/SampleCode/quickstart/cpp. "BasicOperations.cpp" is the most simplest application to just test Apache Geode Native Client (as referred at he above sample CMakeLists.txt).

 

Anyhow, let's enjoy Apache Geode Native Client on macOS.