c++ubuntuprotocol-buffersproto

Unable to build protobuf 2.4.1 on Ubuntu


When I was trying to run make command to build protobuf on Ubuntu 20, I faced this error

google/protobuf/compiler/command_line_interface.cc:913:55: error: cannot bind rvalue reference of type ‘std::__cxx11::basic_string<char>&&’ to lvalue of type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}
  913 |       proto_path_.push_back(make_pair<string, string>(virtual_path, disk_path));
      |                                                       ^~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/string:40,
                 from ./google/protobuf/stubs/common.h:41,
                 from ./google/protobuf/compiler/command_line_interface.h:41,
                 from google/protobuf/compiler/command_line_interface.cc:35:

Anyone know how to fix it?


Solution

  • Three things spring to mind:

    1. You may need to specify a given C++ version e.g. -std=c++11

    2. It appears you can install multiple versions of gcc on Ubuntu 20 as well: https://linuxize.com/post/how-to-install-gcc-on-ubuntu-20-04/

    3. If all else fails, you could create a docker image to perform your compilation, base the docker image on an older version of Ubuntu/Debian and/or use an older compiler. Also see this: https://askubuntu.com/questions/1229774/how-to-use-an-older-version-of-gcc