java 如何为 protoc(协议缓冲区)获取预编译的 linux 二进制文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6924838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:55:03  来源:igfitidea点击:

How do I get a precompiled linux binary for protoc ( protocol buffers )?

javaantprotocol-buffers

提问by YoK

My build server is linux based. I need protoc to integrate it to my ant based build system.

我的构建服务器是基于 linux 的。我需要 protoc 将它集成到我的基于 ant 的构建系统中。

I use following in build.xml for same:

我在 build.xml 中使用以下相同:

    <exec executable="tools/protoc.exe" failonerror="true">
        <arg value="--java_out=../protos/java/generated" />
        <arg value="--proto_path=../protos/proto" />
        <arg value="../protos/proto/*.proto" />
    </exec>

I found windows binary , but didn't find linux binary for protoc.

我找到了 windows binary ,但没有找到 protoc 的 linux binary 。

Any help to find one or build statically linked protoc binary would be nice.

找到一个或构建静态链接的 protoc 二进制文件的任何帮助都会很好。

回答by Jon Skeet

Have you tried just downloading the main protobuf projectand following the installation instructions? I seem to remember it's pretty straightforward if you only need the binary:

您是否尝试过下载主要的 protobuf 项目并按照安装说明进行操作?我似乎记得如果您只需要二进制文件就非常简单:

$ ./autogen.sh
$ ./configure
$ make

(You probably don't need make installin this case, if you only need the protocbinary. Just find out where it's been built and copy it.)

make install在这种情况下,您可能不需要,如果您只需要protoc二进制文件。只需找出它的构建位置并复制它即可。)

回答by Ben

Precompiled binaries for the latest release are on the official releases pageon GitHub. Previous versions can be found on the Maven repository.

最新版本的预编译二进制文件位于 GitHub上的官方发布页面。以前的版本可以在Maven 存储库中找到。

回答by ISanych

For java you also could use https://github.com/os72/protoc-jarwhich already contains binaries for different platforms.

对于 java,您还可以使用https://github.com/os72/protoc-jar,它已经包含不同平台的二进制文件。

回答by Anne van Rossum

On Ubuntu (since 12.04) you can find protobuf-compilerin the repository.

在 Ubuntu(自 12.04 起)上,您可以protobuf-compiler在存储库中找到。

sudo apt-get install protobuf-compiler

$> protoc --version
libprotoc 2.6.1

And you might as well want to install the header files:

您可能还想安装头文件:

sudo aptitude install libprotobuf-dev

回答by Vishal Keshav

In case you want to compile only protocbinary for any platform, then follow these steps:

如果您只想protoc任何平台编译二进制文件,请按照以下步骤操作:

Under protobuf project directory

protobuf项目目录下

./autogen.sh
cd protoc-artifacts
./build-protoc.sh linux x86_64 protoc

Once, the protoc.exeis built in protobuf/protoc-artifacts/target/linux/x86_64/protocrename it to protoc

一次,protoc.exe内置的protobuf/protoc-artifacts/target/linux/x86_64/protoc重命名为protoc

mv protobuf/protoc-artifacts/target/linux/x86_64/protoc.exe protobuf/protoc-artifacts/target/linux/x86_64/protoc

回答by Uday Chauhan

1) Download binary from the url https://github.com/protocolbuffers/protobuf/releases

1) 从 url https://github.com/protocolbuffers/protobuf/releases下载二进制文件

2) extract and keep the directory at particular location (/user/app/protoc)

2) 提取目录并将其保存在特定位置 ( /user/app/protoc)

3) add the entry in /usr//.bash_profile as

3) 在 /usr//.bash_profile 中添加条目为

export PROTOC_HOME=/user/app/protoc
export PATH=$PROTOC_HOME/bin:$PATH

4) refresh file $source /usr/<username>/.bash_profile

4)刷新文件 $source /usr/<username>/.bash_profile

Other option is run the following command one by one after downloading the repository :

另一个选项是下载存储库后一一运行以下命令:

sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin
sudo cp -R protoc/include/* $BASE/include