JavaRanch Home    
 
This page:         last edited 19 November 2011         What's Changed?         Edit

Protoc Independent Binary - Linux   

Protocol buffers(1) can be used as a light weight format to communicate with other systems over a network. The protobuf compiler is not written in java, which means each OS needs a separate binary to compile language specific objects from a .proto source file. In windows the binary file protoc.exe does the job. It does not require additional libraries to be installed on the client's machine to get it to work.

On linux, the 'protoc' binary file is dependent on shared libraries when the default compilations options are used. Files like libprotoc.so are dynamically linked when protoc is invoked. To avoid depending on these libraries use the following commands while compiling protoc from its source

./configure --disable-shared

make install

You can verify the libraries that the protoc binary depends on by using the ldd command (2)

ldd /usr/local/bin/protoc

linux-vdso.so.1 => (0x00007fff427ba000)

libz.so.1 => /lib/libz.so.1 (0x00007fe2e1485000)

libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fe2e1171000)

libm.so.6 => /lib/libm.so.6 (0x00007fe2e0eed000)

libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fe2e0cd6000)

libpthread.so.0 => /lib/libpthread.so.0 (0x00007fe2e0ab9000)

libc.so.6 => /lib/libc.so.6 (0x00007fe2e0736000)

/lib64/ld-linux-x86-64.so.2 (0x00007fe2e16b9000)

The protoc executable that you get as a result is a little bulky (8 MB+). Another option you can try is to use a solution like Ermine (Commercial) (4) or Statifier (Free) (3). These solutions bundle an executable with all its dependencies on linux. At the time of this writing using Statifier on protoc causes a Segmentation fault. Using Ermine produces a binary that was working and free of dependencies.

One gotcha to watch out for while comping the binary is to ensure you execute the commands 'make uninstall' and 'make cleandist'. These commands wipe out traces of source files and binaries left over from a previous compilation. Take care to differentiate between /usr/local/bin/protoc and /usr/bin/protoc while you check dependencies with ldd (2). Update your linker's cache using 'sudo ldconfig' after compiling a binary.

Note that the '--disable-shared' option should work equally well on another operating system like a Mac.

References

(1) http://code.google.com/p/protobuf/

(2) http://en.wikipedia.org/wiki/Dynamic_linker#GNU.2FLinux

(3) http://www.magicermine.com/

(4) http://statifier.sourceforge.net/


JavaRanchContact us — Copyright © 1998-2012 Paul Wheaton