Creating C++ libraries for operators and native functions

To enable operators and native functions, you must compile with the appropriate include file paths and options and link any shared libraries against the correct runtime libraries.

The reason for this requirement is twofold. Many operators and native functions must build C++ shared libraries that implement some functionality. Some C++ libraries also attempt to access the Teracloud® Streams runtime environment.

One method is to issue the appropriate commands from within a makefile. The following example is a boilerplate header that can be used in a makefile.


ifeq ($(PLATFORM),ppc64le)
  CXX=/opt/at8.0/bin/g++
endif
SPL_PKGCFG=$(STREAMS_INSTALL)/bin/dst-pe-pkg-config.sh
SPL_PKG=dst-spl-pe-install
SPL_COMPILE_OPTIONS = `$(SPL_PKGCFG) --cflags $(SPL_PKG)`
SPL_LINK_OPTIONS = `$(SPL_PKGCFG) --libs $(SPL_PKG)`

When this code is included at the beginning of the makefile, C++ compiles can add $(SPL_COMPILE_OPTIONS) to any g++ compile line to provide needed compile options, and include directories. In a similar manner, $(SPL_LINK_OPTIONS) can be added to the creation of the shared lib to provide library paths and names.

A sample makefile that demonstrates this code is shown in the following example:

ifeq ($(PLATFORM),ppc64le)
  CXX=/opt/at8.0/bin/g++
endif
SPL_PKGCFG=$(STREAMS_INSTALL)/bin/dst-pe-pkg-config.sh
SPL_PKG=dst-spl-pe-install
SPL_COMPILE_OPTIONS = `$(SPL_PKGCFG) --cflags $(SPL_PKG)`
SPL_LINK_OPTIONS = `$(SPL_PKGCFG) --libs $(SPL_PKG)`

.PHONY: clean distclean

all: lib/libMySampleLib.so

lib/MySampleLib.o: src/MySampleLib.cpp include/MySampleLib.h
      @echo Compiling 'src/MySampleLib.cpp' ...
      @$(CXX) -Wall -fPIC -I include $(SPL_COMPILE_OPTIONS) \
           -c src/MySampleLib.cpp -o $@

lib/libMySampleLib.so: lib/MySampleLib.o
      @echo Building C++ shared library '$@'
      @$(CXX) -shared -o $@ $(SPL_LINK_OPTIONS) $< clean:
      rm -rf lib/MySampleLib.o lib/libMySampleLib.so

distclean: clean