LATEST VERSION: 9.2 - RELEASE NOTES
Pivotal GemFire® Client v9.2

Developing C++ Programs on Linux

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

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

Step 1. Set Environment Variables

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

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

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

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$GEODE/include Specifies the 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 $GEODE/lib Tells the linker to look in $GEODE/lib for libraries on which the client library depends.
-L$GEODE/lib Tells the linker where to find the named libraries.
-o durableclient Tells the linker to output an object file named ‘durableclient’.
-lpivotal-gemfire Links the client C++ cache library to the compiled executable.

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

Compiling and Dynamically Linking on Linux for 32-bit

g++ \
-D_REENTRANT \
-O3 \
-Wall \
-m32 \
-I$GEODE/include \
cpp/DurableClient.cpp \
cpp/plugins/DurableCacheListener.cpp \
-o cpp/DurableClient \
-L$GEODE/lib \
-Wl,-rpath,$GEODE/lib \
-lpivotal-gemfire
-std=c++11 \
-lstdc++ \
-lgcc_s \
-lc

Compiling and Dynamically Linking on Linux for 64-bit

g++ \
-D_REENTRANT \
-O3 \
-Wall \
-m64 \
-I$GEODE/include \
cpp/DurableClient.cpp \
cpp/plugins/DurableCacheListener.cpp \
-o cpp/DurableClient \
-L$GEODE/lib \
-Wl,-rpath,$GEODE/lib \
-lpivotal-gemfire \
-std=c++11 \
-lstdc++ \
-lgcc_s \
-lc

Step 3. Make Sure the Client Library Can Be Loaded

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

To ensure that the 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 GemFire product directory.