安装protobuf
# 安装protobuf
本文介绍安装protobuf的步骤。
访问官网 (opens new window),下载指定版本的源码。
# 安装protobuf
操作步骤如下:
curl -O https://github.91chi.fun//https://github.com//protocolbuffers/protobuf/archive/refs/tags/v3.19.4.tar.gz
cd ./protobuf-3.19.4
./autogen.sh
./configure
make
make install
安装完成之后验证是否安装成功
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4 which protoc
/usr/local/bin/protoc
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4 protoc --version
libprotoc 3.19.4
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4
# 切换protobuf版本
假设当前系统中之前有按前述方法安装过多个版本的protobuf,那么若想方便地切换protof版本,只需要进入对应目录,执行make install即可。
通过测试得知,/usr/local/bin/protoc文件仅仅是protoc的其中一个文件,仅替换该文件,生成的pb文件并不正确。为此,重新到对应版本下,重新执行下make install即可。 基于不同版本的protobuf,生成的pb文件内容会有所区别。
操作过程示例如下:
wangshibiao@192 ~/Downloads/tmp ll
total 0
drwxr-xr-x@ 61 wangshibiao staff 1.9K 4 8 2021 protobuf-3.10.0
drwxr-xr-x 85 wangshibiao staff 2.7K 2 14 18:48 protobuf-3.19.4
wangshibiao@192 ~/Downloads/tmp
wangshibiao@192 ~/Downloads/tmp cd ./protobuf-3.10.0
wangshibiao@192 ~/Downloads/tmp/protobuf-3.10.0 make install
Making install in .
make[2]: Nothing to be done for `install-exec-am'.
./install-sh -c -d '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 protobuf.pc protobuf-lite.pc '/usr/local/lib/pkgconfig'
Making install in src
.././install-sh -c -d '/usr/local/lib'
/bin/sh ../libtool --mode=install /usr/bin/install -c libprotobuf-lite.la libprotobuf.la libprotoc.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.21.dylib /usr/local/lib/libprotobuf-lite.21.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotobuf-lite.21.dylib libprotobuf-lite.dylib || { rm -f libprotobuf-lite.dylib && ln -s libprotobuf-lite.21.dylib libprotobuf-lite.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.lai /usr/local/lib/libprotobuf-lite.la
libtool: install: /usr/bin/install -c .libs/libprotobuf.21.dylib /usr/local/lib/libprotobuf.21.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotobuf.21.dylib libprotobuf.dylib || { rm -f libprotobuf.dylib && ln -s libprotobuf.21.dylib libprotobuf.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotobuf.lai /usr/local/lib/libprotobuf.la
libtool: install: /usr/bin/install -c .libs/libprotoc.21.dylib /usr/local/lib/libprotoc.21.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotoc.21.dylib libprotoc.dylib || { rm -f libprotoc.dylib && ln -s libprotoc.21.dylib libprotoc.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotoc.lai /usr/local/lib/libprotoc.la
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.a /usr/local/lib/libprotobuf-lite.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf-lite.a
libtool: install: ranlib /usr/local/lib/libprotobuf-lite.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf-lite.a(io_win32.o) has no symbols
libtool: install: /usr/bin/install -c .libs/libprotobuf.a /usr/local/lib/libprotobuf.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf.a
libtool: install: ranlib /usr/local/lib/libprotobuf.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf.a(io_win32.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf.a(error_listener.o) has no symbols
libtool: install: /usr/bin/install -c .libs/libprotoc.a /usr/local/lib/libprotoc.a
libtool: install: chmod 644 /usr/local/lib/libprotoc.a
libtool: install: ranlib /usr/local/lib/libprotoc.a
.././install-sh -c -d '/usr/local/bin'
/bin/sh ../libtool --mode=install /usr/bin/install -c protoc '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/protoc /usr/local/bin/protoc
.././install-sh -c -d '/usr/local/include'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/descriptor.proto google/protobuf/any.proto google/protobuf/api.proto google/protobuf/duration.proto google/protobuf/empty.proto google/protobuf/field_mask.proto google/protobuf/source_context.proto google/protobuf/struct.proto google/protobuf/timestamp.proto google/protobuf/type.proto google/protobuf/wrappers.proto '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler'
/usr/bin/install -c -m 644 google/protobuf/compiler/plugin.proto '/usr/local/include/google/protobuf/compiler'
.././install-sh -c -d '/usr/local/include'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/any.pb.h google/protobuf/api.pb.h google/protobuf/any.h google/protobuf/arena.h google/protobuf/arena_impl.h google/protobuf/arenastring.h google/protobuf/descriptor_database.h google/protobuf/descriptor.h google/protobuf/descriptor.pb.h google/protobuf/duration.pb.h google/protobuf/dynamic_message.h google/protobuf/empty.pb.h google/protobuf/extension_set.h google/protobuf/extension_set_inl.h google/protobuf/field_mask.pb.h google/protobuf/generated_enum_reflection.h google/protobuf/generated_enum_util.h google/protobuf/generated_message_reflection.h google/protobuf/generated_message_table_driven.h google/protobuf/generated_message_util.h google/protobuf/has_bits.h google/protobuf/implicit_weak_message.h google/protobuf/inlined_string_field.h google/protobuf/map_entry.h google/protobuf/map_entry_lite.h google/protobuf/map_field.h google/protobuf/map_field_inl.h google/protobuf/map_field_lite.h google/protobuf/map.h google/protobuf/map_type_handler.h google/protobuf/message.h google/protobuf/message_lite.h google/protobuf/metadata.h google/protobuf/metadata_lite.h google/protobuf/parse_context.h google/protobuf/port.h google/protobuf/port_def.inc google/protobuf/port_undef.inc google/protobuf/reflection.h google/protobuf/reflection_ops.h '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/python'
/usr/bin/install -c -m 644 google/protobuf/compiler/python/python_generator.h '/usr/local/include/google/protobuf/compiler/python'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/php'
/usr/bin/install -c -m 644 google/protobuf/compiler/php/php_generator.h '/usr/local/include/google/protobuf/compiler/php'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/cpp'
/usr/bin/install -c -m 644 google/protobuf/compiler/cpp/cpp_generator.h '/usr/local/include/google/protobuf/compiler/cpp'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/objectivec'
/usr/bin/install -c -m 644 google/protobuf/compiler/objectivec/objectivec_generator.h google/protobuf/compiler/objectivec/objectivec_helpers.h '/usr/local/include/google/protobuf/compiler/objectivec'
.././install-sh -c -d '/usr/local/include/google/protobuf/stubs'
/usr/bin/install -c -m 644 google/protobuf/stubs/callback.h google/protobuf/stubs/bytestream.h google/protobuf/stubs/casts.h google/protobuf/stubs/common.h google/protobuf/stubs/fastmem.h google/protobuf/stubs/hash.h google/protobuf/stubs/logging.h google/protobuf/stubs/macros.h google/protobuf/stubs/map_util.h google/protobuf/stubs/mutex.h google/protobuf/stubs/once.h google/protobuf/stubs/platform_macros.h google/protobuf/stubs/port.h google/protobuf/stubs/status.h google/protobuf/stubs/stl_util.h google/protobuf/stubs/stringpiece.h google/protobuf/stubs/strutil.h google/protobuf/stubs/template_util.h '/usr/local/include/google/protobuf/stubs'
.././install-sh -c -d '/usr/local/include/google/protobuf/io'
/usr/bin/install -c -m 644 google/protobuf/io/io_win32.h google/protobuf/io/coded_stream.h google/protobuf/io/gzip_stream.h google/protobuf/io/printer.h google/protobuf/io/strtod.h google/protobuf/io/tokenizer.h google/protobuf/io/zero_copy_stream.h google/protobuf/io/zero_copy_stream_impl.h google/protobuf/io/zero_copy_stream_impl_lite.h '/usr/local/include/google/protobuf/io'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/repeated_field.h google/protobuf/service.h google/protobuf/source_context.pb.h google/protobuf/struct.pb.h google/protobuf/text_format.h google/protobuf/timestamp.pb.h google/protobuf/type.pb.h google/protobuf/unknown_field_set.h google/protobuf/wire_format.h google/protobuf/wire_format_lite.h google/protobuf/wrappers.pb.h '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/java'
/usr/bin/install -c -m 644 google/protobuf/compiler/java/java_generator.h google/protobuf/compiler/java/java_names.h '/usr/local/include/google/protobuf/compiler/java'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler'
/usr/bin/install -c -m 644 google/protobuf/compiler/code_generator.h google/protobuf/compiler/command_line_interface.h google/protobuf/compiler/importer.h google/protobuf/compiler/parser.h google/protobuf/compiler/plugin.h google/protobuf/compiler/plugin.pb.h '/usr/local/include/google/protobuf/compiler'
.././install-sh -c -d '/usr/local/include/google/protobuf/util'
/usr/bin/install -c -m 644 google/protobuf/util/type_resolver.h google/protobuf/util/delimited_message_util.h google/protobuf/util/field_comparator.h google/protobuf/util/field_mask_util.h google/protobuf/util/json_util.h google/protobuf/util/time_util.h google/protobuf/util/type_resolver_util.h google/protobuf/util/message_differencer.h '/usr/local/include/google/protobuf/util'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/ruby'
/usr/bin/install -c -m 644 google/protobuf/compiler/ruby/ruby_generator.h '/usr/local/include/google/protobuf/compiler/ruby'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/csharp'
/usr/bin/install -c -m 644 google/protobuf/compiler/csharp/csharp_generator.h google/protobuf/compiler/csharp/csharp_names.h '/usr/local/include/google/protobuf/compiler/csharp'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/js'
/usr/bin/install -c -m 644 google/protobuf/compiler/js/js_generator.h google/protobuf/compiler/js/well_known_types_embed.h '/usr/local/include/google/protobuf/compiler/js'
wangshibiao@192 ~/Downloads/tmp/protobuf-3.10.0 which protoc
/usr/local/bin/protoc
wangshibiao@192 ~/Downloads/tmp/protobuf-3.10.0 protoc --version
libprotoc 3.10.0
wangshibiao@192 ~/Downloads/tmp/protobuf-3.10.0
wangshibiao@192 ~/Downloads/tmp/protobuf-3.10.0 cd ../protobuf-3.19.4
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4 make install
Making install in .
make[2]: Nothing to be done for `install-exec-am'.
./install-sh -c -d '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 protobuf.pc protobuf-lite.pc '/usr/local/lib/pkgconfig'
Making install in src
.././install-sh -c -d '/usr/local/lib'
/bin/sh ../libtool --mode=install /usr/bin/install -c libprotobuf-lite.la libprotobuf.la libprotoc.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.30.dylib /usr/local/lib/libprotobuf-lite.30.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotobuf-lite.30.dylib libprotobuf-lite.dylib || { rm -f libprotobuf-lite.dylib && ln -s libprotobuf-lite.30.dylib libprotobuf-lite.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.lai /usr/local/lib/libprotobuf-lite.la
libtool: install: /usr/bin/install -c .libs/libprotobuf.30.dylib /usr/local/lib/libprotobuf.30.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotobuf.30.dylib libprotobuf.dylib || { rm -f libprotobuf.dylib && ln -s libprotobuf.30.dylib libprotobuf.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotobuf.lai /usr/local/lib/libprotobuf.la
libtool: install: /usr/bin/install -c .libs/libprotoc.30.dylib /usr/local/lib/libprotoc.30.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libprotoc.30.dylib libprotoc.dylib || { rm -f libprotoc.dylib && ln -s libprotoc.30.dylib libprotoc.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libprotoc.lai /usr/local/lib/libprotoc.la
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.a /usr/local/lib/libprotobuf-lite.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf-lite.a
libtool: install: ranlib /usr/local/lib/libprotobuf-lite.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf-lite.a(io_win32.o) has no symbols
libtool: install: /usr/bin/install -c .libs/libprotobuf.a /usr/local/lib/libprotobuf.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf.a
libtool: install: ranlib /usr/local/lib/libprotobuf.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf.a(io_win32.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /usr/local/lib/libprotobuf.a(error_listener.o) has no symbols
libtool: install: /usr/bin/install -c .libs/libprotoc.a /usr/local/lib/libprotoc.a
libtool: install: chmod 644 /usr/local/lib/libprotoc.a
libtool: install: ranlib /usr/local/lib/libprotoc.a
.././install-sh -c -d '/usr/local/bin'
/bin/sh ../libtool --mode=install /usr/bin/install -c protoc '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/protoc /usr/local/bin/protoc
.././install-sh -c -d '/usr/local/include'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/any.proto google/protobuf/api.proto google/protobuf/descriptor.proto google/protobuf/duration.proto google/protobuf/empty.proto google/protobuf/field_mask.proto google/protobuf/source_context.proto google/protobuf/struct.proto google/protobuf/timestamp.proto google/protobuf/type.proto google/protobuf/wrappers.proto '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler'
/usr/bin/install -c -m 644 google/protobuf/compiler/plugin.proto '/usr/local/include/google/protobuf/compiler'
.././install-sh -c -d '/usr/local/include'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/any.h google/protobuf/any.pb.h google/protobuf/api.pb.h google/protobuf/arena.h google/protobuf/arena_impl.h google/protobuf/arenastring.h google/protobuf/descriptor.h google/protobuf/descriptor.pb.h google/protobuf/descriptor_database.h google/protobuf/duration.pb.h google/protobuf/dynamic_message.h google/protobuf/empty.pb.h google/protobuf/explicitly_constructed.h google/protobuf/extension_set.h google/protobuf/extension_set_inl.h google/protobuf/field_access_listener.h google/protobuf/field_mask.pb.h google/protobuf/generated_enum_reflection.h google/protobuf/generated_enum_util.h google/protobuf/generated_message_bases.h google/protobuf/generated_message_reflection.h google/protobuf/generated_message_table_driven.h google/protobuf/generated_message_table_driven_lite.h google/protobuf/generated_message_tctable_decl.h google/protobuf/generated_message_tctable_impl.h google/protobuf/generated_message_tctable_impl.inc google/protobuf/generated_message_util.h google/protobuf/has_bits.h google/protobuf/implicit_weak_message.h google/protobuf/inlined_string_field.h google/protobuf/map.h google/protobuf/map_entry.h google/protobuf/map_entry_lite.h google/protobuf/map_field.h google/protobuf/map_field_inl.h google/protobuf/map_field_lite.h google/protobuf/map_type_handler.h google/protobuf/message.h google/protobuf/message_lite.h google/protobuf/metadata.h '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/python'
/usr/bin/install -c -m 644 google/protobuf/compiler/python/python_generator.h '/usr/local/include/google/protobuf/compiler/python'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/php'
/usr/bin/install -c -m 644 google/protobuf/compiler/php/php_generator.h '/usr/local/include/google/protobuf/compiler/php'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/cpp'
/usr/bin/install -c -m 644 google/protobuf/compiler/cpp/cpp_file.h google/protobuf/compiler/cpp/cpp_generator.h google/protobuf/compiler/cpp/cpp_helpers.h google/protobuf/compiler/cpp/cpp_names.h '/usr/local/include/google/protobuf/compiler/cpp'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/objectivec'
/usr/bin/install -c -m 644 google/protobuf/compiler/objectivec/objectivec_generator.h google/protobuf/compiler/objectivec/objectivec_helpers.h '/usr/local/include/google/protobuf/compiler/objectivec'
.././install-sh -c -d '/usr/local/include/google/protobuf/stubs'
/usr/bin/install -c -m 644 google/protobuf/stubs/bytestream.h google/protobuf/stubs/callback.h google/protobuf/stubs/casts.h google/protobuf/stubs/common.h google/protobuf/stubs/hash.h google/protobuf/stubs/logging.h google/protobuf/stubs/macros.h google/protobuf/stubs/map_util.h google/protobuf/stubs/mutex.h google/protobuf/stubs/once.h google/protobuf/stubs/platform_macros.h google/protobuf/stubs/port.h google/protobuf/stubs/status.h google/protobuf/stubs/stl_util.h google/protobuf/stubs/stringpiece.h google/protobuf/stubs/strutil.h google/protobuf/stubs/template_util.h '/usr/local/include/google/protobuf/stubs'
.././install-sh -c -d '/usr/local/include/google/protobuf/io'
/usr/bin/install -c -m 644 google/protobuf/io/coded_stream.h google/protobuf/io/gzip_stream.h google/protobuf/io/io_win32.h google/protobuf/io/printer.h google/protobuf/io/strtod.h google/protobuf/io/tokenizer.h google/protobuf/io/zero_copy_stream.h google/protobuf/io/zero_copy_stream_impl.h google/protobuf/io/zero_copy_stream_impl_lite.h '/usr/local/include/google/protobuf/io'
.././install-sh -c -d '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/metadata_lite.h google/protobuf/parse_context.h google/protobuf/port.h google/protobuf/port_def.inc google/protobuf/port_undef.inc google/protobuf/reflection.h google/protobuf/reflection_ops.h google/protobuf/repeated_field.h google/protobuf/repeated_ptr_field.h google/protobuf/service.h google/protobuf/source_context.pb.h google/protobuf/struct.pb.h google/protobuf/text_format.h google/protobuf/timestamp.pb.h google/protobuf/type.pb.h google/protobuf/unknown_field_set.h google/protobuf/wire_format.h google/protobuf/wire_format_lite.h google/protobuf/wrappers.pb.h '/usr/local/include/google/protobuf'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/java'
/usr/bin/install -c -m 644 google/protobuf/compiler/java/java_generator.h google/protobuf/compiler/java/java_kotlin_generator.h google/protobuf/compiler/java/java_names.h '/usr/local/include/google/protobuf/compiler/java'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler'
/usr/bin/install -c -m 644 google/protobuf/compiler/code_generator.h google/protobuf/compiler/command_line_interface.h google/protobuf/compiler/importer.h google/protobuf/compiler/parser.h google/protobuf/compiler/plugin.h google/protobuf/compiler/plugin.pb.h '/usr/local/include/google/protobuf/compiler'
.././install-sh -c -d '/usr/local/include/google/protobuf/util'
/usr/bin/install -c -m 644 google/protobuf/util/delimited_message_util.h google/protobuf/util/field_comparator.h google/protobuf/util/field_mask_util.h google/protobuf/util/json_util.h google/protobuf/util/message_differencer.h google/protobuf/util/time_util.h google/protobuf/util/type_resolver.h google/protobuf/util/type_resolver_util.h '/usr/local/include/google/protobuf/util'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/ruby'
/usr/bin/install -c -m 644 google/protobuf/compiler/ruby/ruby_generator.h '/usr/local/include/google/protobuf/compiler/ruby'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/csharp'
/usr/bin/install -c -m 644 google/protobuf/compiler/csharp/csharp_doc_comment.h google/protobuf/compiler/csharp/csharp_generator.h google/protobuf/compiler/csharp/csharp_names.h google/protobuf/compiler/csharp/csharp_options.h '/usr/local/include/google/protobuf/compiler/csharp'
.././install-sh -c -d '/usr/local/include/google/protobuf/compiler/js'
/usr/bin/install -c -m 644 google/protobuf/compiler/js/js_generator.h '/usr/local/include/google/protobuf/compiler/js'
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4 which protoc
/usr/local/bin/protoc
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4 protoc --version
libprotoc 3.19.4
wangshibiao@192 ~/Downloads/tmp/protobuf-3.19.4
上次更新: 2022-02-15 00:00:15