无法在Ubuntu上构建protobuf 2.4.1

cczfrluj  于 2023-06-21  发布在  其他
关注(0)|答案(2)|浏览(116)

当我试图运行make命令在Ubuntu 20上构建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:

有人知道怎么修吗?

nbysray5

nbysray51#

我想到三件事:
1.您可能需要指定一个给定的C++版本,例如-std=c++11
1.你也可以在Ubuntu 20上安装多个版本的gcc:https://linuxize.com/post/how-to-install-gcc-on-ubuntu-20-04/
1.如果其他方法都失败了,你可以创建一个docker镜像来执行编译,基于Ubuntu/Debian的旧版本和/或使用旧版本的编译器。请看这个:https://askubuntu.com/questions/1229774/how-to-use-an-older-version-of-gcc

zzzyeukh

zzzyeukh2#

在Ubuntu 20上安装gcc 5.3.1允许我使用makeinstall协议2.4.1。
Xenial存储库仍然提供旧版本的gcc。要添加它们,请执行以下操作:

sudo vim /etc/apt/sources.list

添加以下行:

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

安装gcc5

sudo apt update
sudo apt install g++-5 gcc-5

将默认gcc更改为5

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 5
sudo update-alternatives --config gcc

This post was really helpful with the gcc 5 installation and provided the steps above
在安装了gcc 5之后,我可以编译并安装protoc 2.4.1:

sudo ./configure
sudo make
sudo install

我确实需要让protoc知道在哪里寻找共享库

sudo ldconfig

相关问题