Compiling GRPC on Windows

Source: Internet
Author: User

Source code compilation on Windows most open source software is a hassle

Compilation Environment: VS2015 (Grpc Support 2013 and above, 2012 without nuget, more laborious to compile)

Compiling GRPC involves content

    • Grpc
    • Protobuf
    • Grpc_protoc_plugin (This article is compiled with the C + + language, so it only involves Grpc_cpp_plugin)
    • Zlib

After the GRPC code is downloaded, perform the git submodule update--init initialize the dependent submodule

1. Protobuf

Refer to the Readme with CMake to generate project files, compile can

2. Grpc,grpc_protoc_plugin: In the vsprojects has built the project document, uses the vs2015 compiles the basic not to encounter any problem, except:

Grpc_cpp_plugin relies on libprotoc.lib, and Protobuf generates a library name of Libprotocd.lib, which needs to be changed manually

3. zlib Reference Readme

The above steps are very smooth, GRPC and protobuf default is static library compilation, do not encounter link errors, the following attempts to compile Example/cpp/helloworld

1. Modify CmakeFiles.txt, because HelloWorld relies on protobuf need to specify the Protobuf-config.cmake location of Protobuf on the command line

Cmake-dprotobuf_dir=

Grpc I was using my own project files compiled, did not find the corresponding config.cmake, I was the dependence on grpc removed, changed to:

# Minimum CMake requiredcmake_minimum_required (VERSION2.8) # Projectproject (HelloWorld CXX) # Protobufset (protobuf_module_compatible TRUE) find_package (Protobuf CONFIG REQUIRED) message (STATUS"Using protobuf ${protobuf_version}") # grpc#find_package (grpc CONFIG) message (STATUS"Using grpc ${grpc_version}") # GRPC Related directory configuration include_directories ("C:/path/to/grpc/include") link_directories ("C:/path/to/grpc/vsprojects/debug") link_directories ("C:/path/to/grpc/third_party/zlib") link_directories ("c:/path/to/grpc/vsprojects/packages/grpc.dependencies.openssl.1.0.204.1/build/native/lib/v140/win32/debug/ Static") add_definitions (-d_win32_winnt=0x0601) Set (grpc_cpp_plugin_executable"C:/path/to/grpc/vsprojects/debug/grpc_cpp_plugin.exe") # Protofileget_filename_component (Hw_proto".. /.. /protos/helloworld.proto"ABSOLUTE) get_filename_component (Hw_proto_path"${hw_proto}"PATH) # Generated sourcesprotobuf_generate_cpp (Hw_proto_srcs Hw_proto_hdrs"${hw_proto}") Set (Hw_grpc_srcs"${cmake_current_binary_dir}/helloworld.grpc.pb.cc") Set (Hw_grpc_hdrs"${cmake_current_binary_dir}/helloworld.grpc.pb.h") Add_custom_command (OUTPUT"${hw_grpc_srcs}" "${hw_grpc_hdrs}"COMMAND protobuf::p rotoc ARGS--grpc_out"${cmake_current_binary_dir}"-I."${hw_proto_path}"--plugin=protoc-gen-grpc="${grpc_cpp_plugin_executable}"        "${hw_proto}"DEPENDS"${hw_proto}") # Generated include Directoryinclude_directories ("${cmake_current_binary_dir}") # Targets GREETER_[ASYNC_] (client|server) foreach (_target greeter_client greeter_server greeter_async_client greeter_async_server) add_executable (${_target}"${_target}.cc"${hw_proto_srcs} ${hw_grpc_srcs}) # Add corresponding Lib library dependent target_link_libraries (${_target} protobuf::libprotobuf gr PC++_unsecure Grpc++Grpc++_reflection zlib grpc GPR ws2_32 grpc_unsecure libeay32 ssleay32 libvcruntimed) Endforeach () 

2. After generating the project file, you need to modify the Greeter_client/server CRT dependency as/MTd(because the grpc above is/MTD by default)

3. Compile to

4. At this time should encounter can not find a symbol within the GRPC, such as channel, Complete_quque , and so on, the following channel as an example to explain the solution:

Grpc compiled Grpc++.lib, generated channel.obj will be overwritten (for reasons not found, presumably because Grpc.lib compile will also generate Channel.obj)

Delete the channel.obj from the c:\path\to\grpc\vsprojects\intdir\grpc++ in the obj directory and "generate" it in the project (do not regenerate)

5. Solve the above problem, you should be able to generate the executable file

Compiling GRPC on Windows

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.