问题描述
当我尝试在Ubuntu 20上运行make
命令来构建protobuf时,我遇到了这个错误
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:
有人知道如何解决吗?
解决方法
想到三件事:
-
您可能需要指定给定的C ++版本,例如
-std=c++11
-
看来您也可以在Ubuntu 20上安装多个版本的gcc:https://linuxize.com/post/how-to-install-gcc-on-ubuntu-20-04/
-
如果所有其他方法均失败,则可以创建docker映像来执行编译,将docker映像基于较旧版本的Ubuntu / Debian和/或使用较旧的编译器。另请参见:https://askubuntu.com/questions/1229774/how-to-use-an-older-version-of-gcc