Sunday, March 7, 2010

Compiling Google-protobuf without pthreads on Linux

Here is simple tutorial how to create libprotobuf.a that does not require linking with the pthread libraries.

libprotobuf does not support linking with single threaded application, but sometimes it is necessary to do so. Unfortunately it is not possible to do this without some slight modification of the code, but the number of necessary modifications is very small. Only the following four files in src/google/protobuf/stub need some a slight addition: once.h, once.cc, common.cc and once_unittest.cc

A modified package for libprotobuf-2.3.0 can be downloaded from here:

http://metamatix.org/~chris/protobuf-2.3.0-with_single_thread_support.tgz

To make this package work as expected the following three important points should be observed:

  1. -D_SINGLE_THREADED must be appended to the content of the CXXFLAGS environment variable in the shell before running configure.
  2. Use the command ' make PTHREAD_CFLAGS="" ' for building the libprotobuf package.
  3. You project should also be compiled using the -D_SINGLE_THREADED compilation flag and include the modified libprotobuf header files. (for example by appending -I/path/to/modified/libprotobuf/src). Of course the modified libraries should be linked as well (they are stored in .libs subdirectory of the project or at the location specified by the --prefix flag to configure after the project is installed.)

1 comment:

Anonymous said...

Hi, this is exactly what I need. However, would you mind to provide a patch for the current version 2.4.0a?
In any case, thank you very much for your investigation :)

Best regards,
Jonny