Initial knowledge of the Google Multilingual Communication Framework GRPC Series (ii) compiling GRPC

Source: Internet
Author: User
Tags windows visual
This is a creation in Article, where the information may have evolved or changed.

Regardless of the language in which you call GRPC, you must compile GRPC because the client proxy class needs to be generated in addition to the standard data definition classes when generating proto access classes. The client proxy class must be done by the PROTOC plug-in for each of the Grpc languages. These plugins need to be compiled after GRPC to compile the build.

Here's a step-by-step explanation of how to get grpc.

Get GRPC Source code

GRPC is open source framework, project code on GitHub, so first install GitHub.
After GitHub installs, in the specified folder, executes the git command to obtain the GRPC all source code.

git clone  https://github.com/grpc/grpc.git

While the source code package download is available on GitHub's Grpc home page, GRPC's dependent components are not automatically available.

Get the dependent components of GRPC

As with all projects, GRPC also relies on third-party libraries. Because the dependent components have been defined in GRPC by a git .gitmodules file, you can automatically get all the dependent components by simply executing the git command.

git submodule init

Compiling GRPC

Because I am not familiar with other compiling tools, I compile with vs2013 for the time being. There are many problems with the compilation process.

Compile GPR, through

Compile GRPC, error illegal use of the this type as an expression

I look for resources on the Internet, the original C language is not allowed to define variables at any time, all defined variables can only be placed at the beginning of the function, which is the important difference between C and C + +.

The original

static grpc_lb_policy *create_pick_first(grpc_lb_policy_factory *factory,                                         grpc_lb_policy_args *args) {  if (args->num_subchannels == 0) return NULL;  pick_first_lb_policy* p = gpr_malloc(sizeof(*p));  memset(p, 0, sizeof(*p));

Switch

static pick_first_lb_policy *p;static grpc_lb_policy *create_pick_first(grpc_lb_policy_factory *factory,                                         grpc_lb_policy_args *args) {  if (args->num_subchannels == 0) return NULL;  p = gpr_malloc(sizeof(*p));  memset(p, 0, sizeof(*p));

It was compiled.

Compile Boringssl, there are many errors

is mainly

1>d:\projects_framework\grpc\vsprojects\. \SRC\BORINGSSL\ERR_DATA.C: Fatal error C1083:cannot open include file: ' openssl/base.h ': No such file or directory '

I made three attempts.

    • Using Grpc's BORINGSSL project

Problem: Unable to find OpenSSL header file, fix: Add third_party boringssl header file reference in Boringssl vs project

Question: D:\Projects_Framework\grpc\vsprojects\. \third_party\boringssl\crypto\asn1\t_pkey.c ': No such file or directory

Problem: There are many redefinition. Workaround: Remove OpenSSL's package dependencies from the header file reference, possibly due to OpenSSL duplication of the Third_party

But still cannot compile through

    • Instead of using Grpc's BORINGSSL project, use CMake to generate Boringssl vsproj directly.

Requires Perl, go, yasm support
Perl installation can
Golang installation can be
Yasm is an executable exe that is not installed, click Advanced in CMake, and set the path in Cmake_asm_nasm_compiler.
But I see in Boringssl's documentation that BORINGSSL cannot be compiled in Windows Visual Studio. Can only be compiled with ninja.
But consider Grpc's VS project Boringssl not only Boringssl original project files, but also a grpc to add their own files, even if compiled through, can no longer grpc use, so there is no specific attempt to ninja method.

    • Use the py script inside the Grpc Boringssl

I found a file in the Grpc folder: src\boringssl\gen_build_yaml.py . Do not know what to do, after installing Python run this script, generated a lot of ASM files. The compilation result could not be generated.

After many attempts did not compile successfully boringssl, GRPC on the GitHub message board also said Boringssl compiled. If any friend compiles successfully, please tell me the method.

Compiling zlib

There is also a Z project in the GRPC vs solution that contains the Zlib dependency library, which is also compiled directly from vs. But I found that the Z project was all zlib files, no extra files, so I compiled the zlib separately in the directory of the Grpc folder third_party\zlib .
Build Zlib's Vcproj project through CMake and compile it in vs.

Other projects, such as compiling grpc_dll, are passed

At this point, GRPC's core components are all compiled except Boringssl. I worry that when using C + + call GRPC due to the lack of BORINGSSL will cause the compilation, but observe GRPC C + + example, just rely on OpenSSL, and do not rely on BORINGSSL, specific configuration reference my article "C + + call GRPC."

Compiling Protobuffer

GRPC relies on Protobuffer for message encoding and therefore relies on protobuffer.
Protobuffer compilation method in the documentthird_party\protobuf\cmake\readme.md
Using CMake to generate vs solution protobuf.sln, compile through.

Compiling the Protoc Grpc plugin

Copy Protobuf's release folder to Third_party\protobuf\cmake
Open the Grpc_protoc_plugins.sln, compile all the projects and pass smoothly.
Generate all Grpc plugins for Protoc

grpc_cpp_plugin.exegrpc_csharp_plugin.exegrpc_objective_c_plugin.exegrpc_python_plugin.exegrpc_ruby_plugin.exe

The following article describes how to use these plugins.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.