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)
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.
||Required to compile Linux programs in a thread-safe way.|
||Enables 32-bit or 64-bit compilation.|
||Specifies the client
The following table lists the linker switches that must be present on the command line when dynamically linking to the GemFire library.
||Tells the linker to look in
||Tells the linker where to find the named libraries.|
||Tells the linker to output an object file named ‘durableclient’.|
||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.