LATEST VERSION: 9.0.5 - CHANGELOG
Pivotal GemFire® Native Client v9.0

Developing C++ Programs on Linux

This section describes how to build and run a native client application on Linux.

Note: When compiling external projects or applications that are used or referenced by the Geode native client, make sure that you compile them for the same target architecture as your native client installation. For example, if you installed the 64-bit (x86) version of the native client, compile your external projects for 64-bit (x86) architecture.

Step 1. Set Environment Variables

Set the native client environment variables on each Linux host. For each case, product-dir is the path to the native client product directory.

For Bourne and Korn shells (sh, ksh, bash)

GFCPP=product-dir;export GFCPP
PATH=$GFCPP/bin:$PATH;export PATH
LD_LIBRARY_PATH=$GFCPP/lib:$LD_LIBRARY_PATH;export LD_LIBRARY_PATH

Step 2. Compile C++ Clients and Dynamically Link Them to the GemFire Library

On Linux, the g++ compiler is supported. To build and link a C++ client to GemFire on Linux, the compilation command line must include the arguments listed in the following table.

Argument Explanation
-D_REENTRANT Required to compile Linux programs in a thread-safe way.
-m32 or -m64 Enables 32-bit or 64-bit compilation.
-I$GFCPP/include Specifies the native client include directory.

The following table lists the linker switches that must be present on the command line when dynamically linking to the GemFire library.

Argument Explanation
-rpath $GFCPP/lib Tells the linker to look in $GFCPP/lib for libraries on which the native client library depends.
-L$GFCPP/lib Tells the linker where to find the named libraries.
-o durableclient Tells the linker to output an object file named ‘durableclient’.
-lgfcppcache Links the native client C++ cache library to the compiled executable.

The following examples compile and link the $GFCPP/SampleCode/quickstart/cpp/DurableClient.cpp client to the durableclient output file.

Compiling and Dynamically Linking on Linux for 32-bit

g++ \
-D_REENTRANT \
-03 \
-Wall \
-m32 \
-I$GFCPP/include \
cpp/DurableClient.cpp \
cpp/plugins/DurableCacheListener.cpp \
-o cpp/DurableClient \
-L$GFCPP/lib \
-Wl,-rpath,$GFCPP/lib \
-lgfcppcache

Compiling and Dynamically Linking on Linux for 64-bit

g++ \
-D_REENTRANT \
-03 \
-Wall \
-m64 \
-I$GFCPP/include \
cpp/DurableClient.cpp \
cpp/plugins/DurableCacheListener.cpp \
-o cpp/DurableClient \
-L$GFCPP/lib \
-Wl,-rpath,$GFCPP/lib \
-lgfcppcache

Step 3. Make Sure the Native Client Library Can Be Loaded

When the C++ application is dynamically linked to the native client library, the library must be dynamically loadable.

To ensure that the native client library is available for loading, make sure you have added the path product-dir/lib to the LD_LIBRARY_PATH environment variable, where product-dir is the path to the Geode product directory.