Conflict Protobuf version when using Opencv and Tensorflow c++

This is indeed a pretty serious problem! I get the below error similar to you:

[libprotobuf FATAL google/protobuf/stubs/] This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.1.0).  Contact the program author for an update.  If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library.  (Version verification failed in "/build/mir-pkdHET/mir-0.21.0+16.04.20160330/obj-x86_64-linux-gnu/src/protobuf/".)
terminate called after throwing an instance of 'google::protobuf::FatalException'

My workaround:

cd /usr/lib/x86_64-linux-gnu
sudo mkdir BACKUP
sudo mv* ./BACKUP/

Now, the executable under test works, cool. What is not cool, however, is that things like gedit no longer work without running from a shell that has the BACKUP path added to LD_LIBRARY_PATH :-(
Hopefully there's a better fix out there?

The error indicates that the program was complied using headers (.h files) from protobuf 2.6.1. These headers are typically found in /usr/include/google/protobuf or /usr/local/include/google/protobuf, though they could be in other places depending on your OS and how the program is being built. You need to update these headers to version 3.1.0 and recompile the program.

You should rebuild TensorFlow with a linker script to avoid making third party symbols global in the shared library that Bazel creates. This is how the Android Java/JNI library for TensorFlow is able to coexist with the pre-installed protobuf library on the device (look at the build rules in tensorflow/contrib/android for a working example)

Here's a BUILD file that I adapted from the Android library to do this:

package(default_visibility = ["//visibility:public"])

licenses(["notice"])  # Apache 2.0




# Build the native .so.
# bazel build //tensorflow/contrib/ \
#   --crosstool_top=//external:android/crosstool \
#   --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
#   --cpu=armeabi-v7a
LINKER_SCRIPT = "//tensorflow/contrib/"

    name = "",
    srcs = [],
    copts = tf_copts() + [
    linkopts = if_android([
        "-z defs",
        "-Wl,--version-script",  # This line must be directly followed by LINKER_SCRIPT.
    linkshared = 1,
    linkstatic = 1,
    tags = [
    deps = [

And the contents of

    extern "C++" {

This will make everything in the tensorflow namespace global and available through the library, while hiding the reset and preventing it from conflicting with protobuf.

(wasted a ton of time on this so I hope it helps!)