Commits

Anonymous committed 2731703

Allow dependents to use pkg-config to figure out what flags to pass to link against protobuf.

  • Participants
  • Parent commits 8d7e71d

Comments (0)

Files changed (6)

 	  cd gtest && $(MAKE) $(AM_MAKEFLAGS) clean; \
 	fi
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = protobuf.pc protobuf-lite.pc
+
 EXTRA_DIST =                                                                 \
   autogen.sh                                                                 \
   generate_descriptor_proto.sh                                               \
   If you already built the package with a different prefix, make sure
   to run "make clean" before building again.
 
+** Compiling dependent packages **
+
+  To compile a package that uses Protocol Buffers, you need to pass
+  various flags to your compiler and linker.  As of version 2.2.0,
+  Protocol Buffers integrates with pkg-config to manage this.  If you
+  have pkg-config installed, then you can invoke it to get a list of
+  flags like so:
+
+    pkg-config --cflags protobuf         # print compiler flags
+    pkg-config --libs protobuf           # print linker flags
+    pkg-config --cflags --libs protobuf  # print both
+
+  For example:
+
+    c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
+
+  Note that packages written prior to the 2.2.0 release of Protocol
+  Buffers may not yet integrate with pkg-config to get flags, and may
+  not pass the correct set of flags to correctly link against
+  libprotobuf.  If the package in question uses autoconf, you can
+  often fix the problem by invoking its configure script like:
+
+    configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
+              LIBS="$(pkg-config --libs protobuf)"
+
+  This will force it to use the correct flags.
+
+  If you are writing an autoconf-based package that uses Protocol
+  Buffers, you should probably use the PKG_CHECK_MODULES macro in your
+  configure script like:
+
+    PKG_CHECK_MODULES([protobuf], [protobuf])
+
+  See the pkg-config man page for more info.
+
+  If you only want protobuf-lite, substitute "protobuf-lite" in place
+  of "protobuf" in these examples.
+
 ** Note for cross-compiling **
 
   The makefiles normally invoke the protoc executable that they just

File configure.ac

 
 AC_CONFIG_SUBDIRS([gtest])
 
-AC_CONFIG_FILES([Makefile src/Makefile ])
+AC_CONFIG_FILES([Makefile src/Makefile protobuf.pc protobuf-lite.pc])
 AC_OUTPUT

File examples/Makefile

 	@touch protoc_middleman
 
 add_person_cpp: add_person.cc protoc_middleman
-	c++ add_person.cc addressbook.pb.cc -lprotobuf -lpthread -o add_person_cpp
+	pkg-config --cflags protobuf  # fails if protobuf is not installed
+	c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
 
 list_people_cpp: list_people.cc protoc_middleman
-	c++ list_people.cc addressbook.pb.cc -lprotobuf -lpthread -o list_people_cpp
+	pkg-config --cflags protobuf  # fails if protobuf is not installed
+	c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
 
 javac_middleman: AddPerson.java ListPeople.java protoc_middleman
 	javac AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java

File protobuf-lite.pc.in

+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf-lite @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+# Commented out because it crashes pkg-config *sigh*:
+#   http://bugs.freedesktop.org/show_bug.cgi?id=13265
+# Conflicts: protobuf

File protobuf.pc.in

+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf @LIBS@ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+# Commented out because it crashes pkg-config *sigh*:
+#   http://bugs.freedesktop.org/show_bug.cgi?id=13265
+# Conflicts: protobuf-lite