PrevUpHomeNext

Appendix - Building RCFProto

Building RCFProto bindings (C#, Java and Python)
Building RCFProto C++ applications
Building RCFProto C# applications
Building RCFProto Java applications
Building RCFProto Python applications

This section provides details on building RCFProto and RCFProto applications, in C++, C#, Java and Python.

Building RCFProto from source is generally only necessary if you are developing on non-Windows platforms. If you are developing on a Windows platform, you can use the RCFProto Windows binary distribution instead, which comes with pre-packaged C#, Java and Python binaries for x86 and x64 architectures.

To build RCFProto from source, you will need the following dependencies:

  • C++ compiler - any reasonably recent compiler will do (gcc 4.x, Visual Studio 2008 or newer, or similar)
  • cmake (2.8 or later)
  • Boost (1.35.0 or later)
  • zlib
  • OpenSSL

Additional dependencies are needed, depending on which language binding you are building.

For C# bindings:

  • .NET SDK
  • Protocol Buffers C# library (Google.ProtocolBuffers.dll). This is a C# port of Google's Protocol Buffer implementation.

For Java bindings:

  • JDK
  • Protocol Buffers Java library. The Protocol Buffers distribution contains relevant build instructions.

For Python bindings:

  • Python interpreter and development libraries.
  • Protocol Buffers Python library. The Protocol Buffers distribution contains relevant build instructions.

RCFProto uses a cmake-based build system. cmake is used to generate a native build system (either Unix makefiles or Visual C++ nmake makefiles). The native build system is then used to build the executables.

To build on Unix-like systems, use cmake with the "Unix Makefiles" generator. From the root directory of the RCFProto source distribution:

mkdir bin
cd bin
cmake -G "Unix Makefiles" ..

This will generate a makefile, and to build RCFProto you then run make:

make

On Windows systems, use cmake with the Visual C++ nmake generator:

mkdir bin
cd bin
cmake -G "NMake Makefiles" ..

This will generate a nmake makefile, which is then built by running nmake from a Visual C++ command prompt:

nmake

When cmake runs, it attempts to automatically locate all dependencies and prints a summary of the dependencies it found. For example, a build on Linux may produce this output:

...
************************************************
*** RCFProto build: Third party dependency summary ***
RCF include path: /home/user/Development/RCF/RCFProto/cpp/src/RCF/include
Boost include path: /home/user/Development/boost_1_44_0
Protobuf include path: /usr/include
Protobuf libs: /usr/lib/libprotobuf.so
Protobuf debug lib: 
Protobuf Java class path: /usr/share/java/protobuf.jar
JNI include paths: /usr/lib/jvm/java-6-openjdk/include/usr/lib/jvm/java-6-openjdk/include/usr/lib/jvm/java-6-openjdk/include
Java compiler: /usr/bin/javac
Java runtime: /usr/bin/java
Java archiver: /usr/bin/jar
Python include paths: /usr/include/python2.7
Python libs: /usr/lib/libpython2.7.so
ZLIB include path: /usr/include
OpenSSL include path: /usr/include
************************************************
...

If you have a dependency installed to a custom location that cmake is unable to locate automatically, you can set the relevant cmake variable:

# Custom path to Protocol Buffers Java library (protobuf.jar)
cmake -G "Unix Makefiles" -DPROTOBUF_JAVA_CLASS_PATH=path/to/protobuf.jar ..

Note that if you are building e.g. Python bindings, you do not need Java-related dependencies (JDK, Protobuf Java class path), and vice versa. The RCFProto build will only build those bindings for which dependencies are present.

C#

The C# build will copy the built binaries to the /csharp/bin folder in the source distribution.

Here is a list of the binaries on a Windows system:

  • csharp/bin/Google.ProtocolBuffers.dll - Protocol Buffers C# assembly.
  • csharp/bin/protoc.exe - required for ProtoGen.exe.
  • csharp/bin/ProtoGen.exe - Protocol Buffers C# code generator.
  • csharp/bin/RCFProto_NET.dll - RCFProto .NET assembly, built with AnyCPU architecture.
  • csharp/bin/x86/RCFProto_NET_impl.dll - RCFProto implementation DLL for x86.
  • csharp/bin/x64/RCFProto_NET_impl.dll - RCFProto implementation DLL for x64.

The Java build will copy the built binaries to the /java/bin folder in the source distribution.

Here is a list of the binaries on a Windows system:

  • java/bin/Google.ProtocolBuffers.jar - Protocol Buffers Java library.
  • java/bin/protoc.exe - Protocol Buffers Java code generator.
  • java/bin/RCFProto.jar - RCFProto Java library.
  • java/bin/x86/RCFProto_Java_impl.dll - RCFProto implementation DLL for x86.
  • java/bin/x64/RCFProto_Java_impl.dll - RCFProto implementation DLL for x64.

Here is a list of the binaries on a Unix x86 system:

  • java/bin/protobuf.jar - Protocol Buffers Java library.
  • java/bin/protoc - Protocol Buffers Java code generator.
  • java/bin/RCFProto.jar - RCFProto Java library.
  • java/bin/x86/libRCFProto_Java_impl.so - RCFProto implementation library for x86.

The Python build will copy the built binaries to the /python/bin folder in the source distribution.

Here is a list of the binaries on a Windows system:

  • python/bin/protoc.exe - Protocol Buffers Python code generator.
  • python/bin/x86/_rcfproto.pyd - RCFProto Python extension DLL for x86.
  • python/bin/x64/_rcfproto.pyd - RCFProto Python extension DLL for x64.

Here is a list of the binaries on a Unix x86 system:

  • python/bin/protoc - Protocol Buffers Python code generator.
  • python/bin/x86/_rcfproto.so - RCFProto Python extension library for x86.

Once the RCFProto Python bindings are built, you will need to install RCFProto into your Python interpreter. To do so, go to the python/src folder and run setup.py:

python setup.py install

At this point you will be able to open a Python interpreter and instantiate RCFProto classes:

from deltavsoft.rcfproto import *
init()
server = RcfProtoServer( TcpEndpoint('0.0.0.0', 50001 ) )
server.Start()

To build C++ applications using RCFProto, you only need to compile RCF.cpp and RCFProto.cpp into your application. If you want to build RCFProto as a DLL or shared library, you will need to define RCF_BUILD_DLL.

There are several other defines that can be used to configure RCFProto:

  • RCF_USE_ZLIB - Build RCFProto with compression support.
  • RCF_USE_OPENSSL - Build RCFProto with OpenSSL-based SSL support.
  • RCF_USE_IPV6 - Build RCFProto with IPV6 support.

You will also need to link to the Protocol Buffers C++ library. The Protocol Buffers package contains instructions on building this library (libprotobuf.dll / libprotobuf.so) .

To generate Protocol Buffers C++ code for your application, use protoc with the --cpp_out option:

protoc Tutorial.proto --cpp_out=.

The RCFProto C++ bindings have no runtime requirements. Your compiler may have its own runtime requirements (for example, Visual C++-based builds with dynamic runtime linking will require the Visual C++ compiler runtimes to be available).

The stock Protocol Buffers implementation from Google does not provide a C# implementation. However, a third party implementation, protobuf-csharp-port, is available which provides a C# implementation matching fairly closely with the Java implementation from Google. RCFProto's C# support is based on this Protocol Buffers implementation.

To build C# applications using RCFProto, you will need to reference the RCFProto_NET.dll assembly, along with the Google.ProtocolBuffers.dll assembly.

To generate Protocol Buffers C# code for your application, use ProtoGen.exe, with the -service_generator_type=GENERIC option:

ProtoGen.exe Tutorial.proto -service_generator_type=GENERIC -output_directory=.

Without the -service_generator_type=GENERIC option, ProtoGen.exe will only generate code for message types, and not for RPC services.

At runtime, your C# application will load RCFProto_NET.dll . When your application calls RCFProto.Init() to initialize RCFProto, RCFProto will then load a native DLL (RCFProto_NET_impl.dll), which contains the RCFProto implementation.

This means that at runtime, RCFProto_NET_impl.dll must be present in a location searched by the Windows DLL loader. Typically this means that RCFProto_NET_impl.dll should be in the same location as the loading executable.

In some cases this may not be possible (for example if you are writing plugins for a hosting application such as IIS). If so, you will need to call the RCFProto.SetNativeDllPath() method, prior to RCFProto.Init(), to explicitly specify the full path from which RCFProto_NET_impl.dll should be loaded.

RCFProto_NET_impl.dll is a native DLL and is provided in both x86 and x64 versions. You will need to make sure you select the right version for your application, or the DLL will not be able to be loaded.

Java applications need to include the paths to RCFProto.jar and Protocol Buffers (e.g. Protocol.Buffers.jar), as part of the class path.

To generate Protocol Buffers Java code, use protoc with the --java_out option:

protoc Tutorial.proto --java_out=.

Java applications need to include the paths to RCFProto.jar and Protocol Buffers (e.g. Protocol.Buffers.jar), as part of the class path.

When RCFProto.init() is called, RCFProto will attempt to load the native RCFProto JNI library (RCFProto_Java_impl.dll on Windows, or libRCFProto_Java_impl.so on Unix). For this to succeed, the java.lib.path variable needs to be configured with the path to the directory where the native JNI library is to be loaded from.

java.lib.path is normally set when the JVM is started. If you find yourself needing to modify java.lib.path after the JVM has started, the following trick may be useful:

// This hack enables us to modify java.lib.path at runtime.
// http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/

String javaLibPath = System.getProperty( "java.library.path" );

// Modify javaLibPath.
// ...

// Set it back again.
System.setProperty( "java.library.path", javaLibPath );
Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );

Python applications need to import the deltavsoft.rcfproto package.

To generate Protocol Buffers Python code, use protoc with the --python_out option:

protoc Tutorial.proto --python_out=.

The RCFProto and Protocol Buffers modules need to be installed into your Python interpreter.


PrevUpHomeNext