protobuf common.h "No such file"

sim picture sim · Aug 16, 2015 · Viewed 27.4k times · Source

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.

Answer

Kenton Varda picture Kenton Varda · Aug 17, 2015

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