protobuf common.h "No such file"

31,993

PATH tells your shell where to search for commands. It does not tell your compiler where to search for headers. To tell your compiler to find headers in a particular directory, you need to use the -I flag. For example:

g++ -I/path/to/protobuf/include -c my-source.cc

You will need to convince your build system to add this flag to the compiler command-line. All reasonable build systems have some way to do this, but the details vary. For autoconf you can specify when you run configure:

./configure CXXFLAGS=-I/path/to/protobuf/include

For cmake I think you can do something like this (not tested):

cmake -DCMAKE_CXX_FLAGS=-I/path/to/protobuf/include

Alternatively, you would probably not have this problem if you installed protobuf to the standard location -- either /usr or /usr/local (hence placing the headers in /usr/include/google/protobuf or /usr/local/include/google/protobuf).

Also note that almost all Linux distributions have a Protobuf package, and you should probably use that rather than installing Protobuf from source code. You will need the -dev or -devel package in order to get headers. On Debian/Ubuntu:

sudo apt-get install libprotobuf-dev protobuf-compiler
Share:
31,993
sim
Author by

sim

Updated on July 09, 2022

Comments

  • sim
    sim almost 2 years

    I am trying to install Caffe, and I am running into this frustrating error. When I run make I get the following:

    CXX .build_release/src/caffe/proto/caffe.pb.cc
    In file included from .build_release/src/caffe/proto/caffe.pb.cc:5:0:
    .build_release/src/caffe/proto/caffe.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory
    compilation terminated.
    make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1
    

    I am using the Google protocol buffer 2.6.1 (https://developers.google.com/protocol-buffers/docs/downloads), and I have indeed added the directory to the PATH. The common.h file is definitely there in the directory (I see it with my own eyes), but somehow it is unable to detect it. I have no clue what to do, and all the solutions from this issue don't seem to work for me.

    Any insight would be appreciated. I suspect I am neglecting a step somewhere, as I am rather new to Linux.

    Thank you very much.

  • PKivolowitz
    PKivolowitz about 7 years
    This doesn't answer the OP's question. stubs is simply not present in the default install of proto3.
  • Kenton Varda
    Kenton Varda about 7 years
    @PKivolowitz Eh? google/protobuf/stubs/common.h is definitely still there and installed: github.com/google/protobuf/blob/master/src/Makefile.am#L85 (And anyway, OP explicitly said they were using 2.6.1.)