Compiling a MapR Streams C Application

When you compile a MapR Streams C application, you must link it with the librdkafka library in the /opt/mapr/lib/ library path and the libjvm library. Also, include the header file directory to ensure that your application references the header file included with MapR Streams C Client.

You can use the following steps to compile the source code with a Makefile that is in the same directory as the source code.

  1. Copy the following content and create a file named Makefile.
    CC= g++
    CCFLAGS= -Wall -I$(HEADERDIR) -g -std=c99
    #Edit JAVA_HOME to be appropriate for your environment
    export LD_LIBRARY_PATH=/opt/mapr/lib:$(JAVA_HOME)/jre/lib/amd64/server 
    LIBDIR= /opt/mapr/lib/
    %.o: %.c
    	gcc $(CCFLAGS) -c $< 
    consumer: consumer.o
    	gcc -o $@ $@.o -lrdkafka -L$(LIBDIR) $(CCFLAGS)
    producer: producer.o
    	gcc -o $@ $@.o -lrdkafka -L$(LIBDIR) $(CCFLAGS)
    all: consumer producer
    	/bin/rm -f *.o consumer producer
  2. For Mac users, locate the following line of code:
    export LD_LIBRARY_PATH=/opt/mapr/lib:$(JAVA_HOME)/jre/lib/amd64/server
    Then, replace that line with the following line of code:
    export DYLD_LIBRARY_PATH=/opt/mapr/lib:$(JAVA_HOME)/jre/lib/server
  3. Based on your environment, edit JAVA_HOME. This ensures that LD_LIBRARY_PATH or DYLD_LIBRARY_PATH will include the full path to the directory containing the libjvm library.
    Note: You can use find / -name libjvm* to determine the JAVA_HOME directory on your machine. However, note that the results of this command include the full path to the libjvm file not just the JAVA_HOME directory.

    For example, JAVA_HOME may be set to Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/ on a Mac and JAVA_HOME may be set to /usr/lib/jvm/java-1.7.0-openjdk- on Linux.

  4. From the directory which contains the Makefile and the source files, run the following commands to compile the source code:
    make clean
    make all

These steps will generate executables named consumer and producer within the same directory as the Makefile.