国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC

這篇具有很好參考價(jià)值的文章主要介紹了win10系統(tǒng) C++環(huán)境 安裝編譯GRPC。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

第一步 下載源碼、更新、cmake編譯:

為了依賴的成功安裝,采用gitee進(jìn)行下載與更新。記得需要安裝git軟件。
安裝命令:
在自己指定的目錄下,鼠標(biāo)右鍵,選擇 git Bash Here
打開命令行

git clone -b v1.34.0 https://gitee.com/mirrors/grpc-framework.git grpc

在grpc的目錄下修改配置文件:.gitmodules
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

復(fù)制下面內(nèi)容替換.gitmodules內(nèi)容:

[submodule "third_party/zlib"]
    path = third_party/zlib
    #url = https://github.com/madler/zlib
    url = https://gitee.com/mirrors/zlib.git
    # When using CMake to build, the zlib submodule ends up with a
    # generated file that makes Git consider the submodule dirty. This
    # state can be ignored for day-to-day development on gRPC.
    ignore = dirty
[submodule "third_party/protobuf"]
    path = third_party/protobuf
    #url = https://github.com/google/protobuf.git
    url = https://gitee.com/local-grpc/protobuf.git
[submodule "third_party/googletest"]
    path = third_party/googletest
    #url = https://github.com/google/googletest.git
    url = https://gitee.com/local-grpc/googletest.git
[submodule "third_party/benchmark"]
    path = third_party/benchmark
    #url = https://github.com/google/benchmark
    url = https://gitee.com/mirrors/google-benchmark.git
[submodule "third_party/boringssl-with-bazel"]
    path = third_party/boringssl-with-bazel
    #url = https://github.com/google/boringssl.git
    url = https://gitee.com/mirrors/boringssl.git
[submodule "third_party/re2"]
    path = third_party/re2
    #url = https://github.com/google/re2.git
    url = https://gitee.com/local-grpc/re2.git
[submodule "third_party/cares/cares"]
    path = third_party/cares/cares
    #url = https://github.com/c-ares/c-ares.git
    url = https://gitee.com/mirrors/c-ares.git
    branch = cares-1_12_0
[submodule "third_party/bloaty"]
    path = third_party/bloaty
    #url = https://github.com/google/bloaty.git
    url = https://gitee.com/local-grpc/bloaty.git
[submodule "third_party/abseil-cpp"]
    path = third_party/abseil-cpp
    #url = https://github.com/abseil/abseil-cpp.git
    url = https://gitee.com/mirrors/abseil-cpp.git
    branch = lts_2020_02_25
[submodule "third_party/envoy-api"]
    path = third_party/envoy-api
    #url = https://github.com/envoyproxy/data-plane-api.git
    url = https://gitee.com/local-grpc/data-plane-api.git
[submodule "third_party/googleapis"]
    path = third_party/googleapis
    #url = https://github.com/googleapis/googleapis.git
    url = https://gitee.com/mirrors/googleapis.git
[submodule "third_party/protoc-gen-validate"]
    path = third_party/protoc-gen-validate
    #url = https://github.com/envoyproxy/protoc-gen-validate.git
    url = https://gitee.com/local-grpc/protoc-gen-validate.git
[submodule "third_party/udpa"]
    path = third_party/udpa
    #url = https://github.com/cncf/udpa.git
    url = https://gitee.com/local-grpc/udpa.git
[submodule "third_party/libuv"]
    path = third_party/libuv
    #url = https://github.com/libuv/libuv.git
    url = https://gitee.com/mirrors/libuv.git

在grpc目錄下,在git 上使用更新命令

cd grpc
git submodule update --init

使用cmake對grpc進(jìn)行編譯。
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

編譯結(jié)束后,使用vs打開目錄中的grpc.sln文件
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
右鍵ALL——BUILD,點(diǎn)擊重新生成。
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

第二步 編寫 .proto 文件

新建一個(gè)C++控制臺項(xiàng)目,新建 demo.proto 文件
文件內(nèi)容:


syntax = "proto3";

package hello;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string message = 1;
}

message HelloReply {
  string message = 1;
}

在資源文件中右鍵添加現(xiàn)有項(xiàng),將demo.proto 文件添加進(jìn)來。
demo.proto里面不能有中文或者utf-8的格式

第三步 生成頭文件與源文件

在自己新建的控制臺項(xiàng)目中,按住Shift + 右鍵 調(diào)處控制臺
接下來我們利用grpc編譯后生成的proc.exe生成proto的頭文件和源文件

D:\cpp_grpc\visualpro\third_party\protobuf\Debug\protoc.exe -I="." --grpc_out="." --plugin=protoc-gen-grpc="D:\cpp_grpc\visualpro\Debug\grpc_cpp_plugin.exe" "demo.proto"
D:\cpp_grpc\visualpro\third_party\protobuf\Debug\protoc.exe --cpp_out=. "demo.proto"

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
生成出來的文件:
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

第四步 配置VS

將這4個(gè)都右鍵添加現(xiàn)有項(xiàng)的方法添加到C++的控制臺項(xiàng)目中去。
開始配置VS
右鍵項(xiàng)目,點(diǎn)擊屬性,選擇c/c++,選擇常規(guī),選擇附加包含目錄

D:\cpp_grpc\grpc\third_party\re2
D:\cpp_grpc\grpc\third_party\address_sorting\include
D:\cpp_grpc\grpc\third_party\abseil-cpp
D:\cpp_grpc\grpc\third_party\protobuf\src
D:\cpp_grpc\grpc\include

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

接下來配置庫路徑, 在鏈接器常規(guī)選項(xiàng)下,點(diǎn)擊附加庫目錄,添加我們需要的庫目錄。

右鍵項(xiàng)目,點(diǎn)擊屬性,選擇鏈接器,選擇附加庫目錄

D:\cpp_grpc\visualpro\third_party\re2\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\types\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\synchronization\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\status\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\random\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\flags\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\debugging\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\container\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\hash\Debug
D:\cpp_grpc\visualpro\third_party\boringssl-with-bazel\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\numeric\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\time\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\base\Debug
D:\cpp_grpc\visualpro\third_party\abseil-cpp\absl\strings\Debug
D:\cpp_grpc\visualpro\third_party\protobuf\Debug
D:\cpp_grpc\visualpro\third_party\zlib\Debug
D:\cpp_grpc\visualpro\Debug
D:\cpp_grpc\visualpro\third_party\cares\cares\lib\Debug

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
另外,我們雖然配置了庫目錄,但還要將要使用的庫鏈接到項(xiàng)目
點(diǎn)擊鏈接器,選擇輸入選項(xiàng),點(diǎn)擊附加依賴項(xiàng),添加依賴的庫名字

libprotobufd.lib
gpr.lib
grpc.lib
grpc++.lib
grpc++_reflection.lib
address_sorting.lib
ws2_32.lib
cares.lib
zlibstaticd.lib
upb.lib
ssl.lib
crypto.lib
absl_bad_any_cast_impl.lib
absl_bad_optional_access.lib
absl_bad_variant_access.lib
absl_base.lib
absl_city.lib
absl_civil_time.lib
absl_cord.lib
absl_debugging_internal.lib
absl_demangle_internal.lib
absl_examine_stack.lib
absl_exponential_biased.lib
absl_failure_signal_handler.lib
absl_flags.lib
absl_flags_config.lib
absl_flags_internal.lib
absl_flags_marshalling.lib
absl_flags_parse.lib
absl_flags_program_name.lib
absl_flags_usage.lib
absl_flags_usage_internal.lib
absl_graphcycles_internal.lib
absl_hash.lib
absl_hashtablez_sampler.lib
absl_int128.lib
absl_leak_check.lib
absl_leak_check_disable.lib
absl_log_severity.lib
absl_malloc_internal.lib
absl_periodic_sampler.lib
absl_random_distributions.lib
absl_random_internal_distribution_test_util.lib
absl_random_internal_pool_urbg.lib
absl_random_internal_randen.lib
absl_random_internal_randen_hwaes.lib
absl_random_internal_randen_hwaes_impl.lib
absl_random_internal_randen_slow.lib
absl_random_internal_seed_material.lib
absl_random_seed_gen_exception.lib
absl_random_seed_sequences.lib
absl_raw_hash_set.lib
absl_raw_logging_internal.lib
absl_scoped_set_env.lib
absl_spinlock_wait.lib
absl_stacktrace.lib
absl_status.lib
absl_strings.lib
absl_strings_internal.lib
absl_str_format_internal.lib
absl_symbolize.lib
absl_synchronization.lib
absl_throw_delegate.lib
absl_time.lib
absl_time_zone.lib
absl_statusor.lib
re2.lib

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

第五步 編寫服務(wù)端代碼:

編寫服務(wù)端代碼:

#include <iostream>
#include <memory>
#include <string>
#include <grpcpp/grpcpp.h>
#include "demo.grpc.pb.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using hello::HelloRequest;
using hello::HelloReply;
using hello::Greeter;
// Logic and data behind the server's behavior.
class GreeterServiceImpl final : public Greeter::Service {
    Status SayHello(ServerContext* context, const HelloRequest* request,
        HelloReply* reply) override {
        std::string prefix("llfc grpc server has received :  ");
        reply->set_message(prefix + request->message());
        return Status::OK;
    }
};
void RunServer() {
    std::string server_address("127.0.0.1:50051");
    GreeterServiceImpl service;
    ServerBuilder builder;
    // Listen on the given address without any authentication mechanism.
    // 監(jiān)聽給定的地址
    builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
    // Register "service" as the instance through which we'll communicate with
    // clients. In this case it corresponds to an *synchronous* service.
    builder.RegisterService(&service);
    // Finally assemble the server.
    std::unique_ptr<Server> server(builder.BuildAndStart());
    std::cout << "Server listening on " << server_address << std::endl;
    // Wait for the server to shutdown. Note that some other thread must be
    // responsible for shutting down the server for this call to ever return.
    server->Wait();
}
int main(int argc, char** argv) {
    RunServer();
    return 0;
}

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
寫完使用x64平臺運(yùn)行一下。

第六步 編寫客戶端代碼:

右鍵添加新建項(xiàng)目,grpcclient客戶端
為了不重新配置一邊,找到當(dāng)前路徑
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言

win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
直接復(fù)制過去,就完成了配置。
還要復(fù)制以下這4個(gè)文件到客戶端,再使用右鍵添加現(xiàn)有項(xiàng),將這4個(gè)添加進(jìn)去。
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言
客戶端代碼:

#include <string>
#include <iostream>
#include <memory>
#include <grpcpp/grpcpp.h>
#include "demo.grpc.pb.h"
using grpc::ClientContext;
using grpc::Channel;
using grpc::Status;
using hello::HelloReply;
using hello::HelloRequest;
using hello::Greeter;
// static method : Greeter::NewStub
class FCClient {
public:
    FCClient(std::shared_ptr<Channel> channel)
        :stub_(Greeter::NewStub(channel)) {
    }
    std::string SayHello(std::string name) {
        ClientContext context;
        HelloReply reply;
        HelloRequest request;
        request.set_message(name);
        Status status = stub_->SayHello(&context, request, &reply);
        if (status.ok()) {
            return reply.message();
        }
        else {
            return "failure " + status.error_message();
        }
    }
private:
    std::unique_ptr<Greeter::Stub> stub_;
};
int main(int argc, char* argv[]) {
    auto channel = grpc::CreateChannel("127.0.0.1:50051", grpc::InsecureChannelCredentials());
    FCClient client(channel);
    // block until get result from RPC server
    std::string result = client.SayHello("hello , llfc.club !");
    printf("get result [%s]\n", result.c_str());
    return 0;
}

運(yùn)行效果:
win10系統(tǒng) C++環(huán)境 安裝編譯GRPC,C++ 基礎(chǔ),c++,開發(fā)語言文章來源地址http://www.zghlxwxcb.cn/news/detail-730882.html

到了這里,關(guān)于win10系統(tǒng) C++環(huán)境 安裝編譯GRPC的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Ubuntu【系統(tǒng)環(huán)境下】【編譯安裝OpenCV】【C++調(diào)用系統(tǒng)opencv庫】

    Ubuntu【系統(tǒng)環(huán)境下】【編譯安裝OpenCV】【C++調(diào)用系統(tǒng)opencv庫】

    本人需要用C++寫代碼,調(diào)用OpenCV庫,且要求OpenCV版本號大于4.1.0 由于使用的是18.04的版本,所以apt安裝OpenCV的版本始終是3.2.0,非常拉胯?。?! 所以只能重新編譯安裝OpenCV 查看當(dāng)前C++調(diào)用的OpenCV代碼 apt 安裝 OpenCV sudo apt install libopencv-dev apt 安裝 OpenCV 并與系統(tǒng)python環(huán)境關(guān)聯(lián)

    2024年02月11日
    瀏覽(25)
  • VMware Workstation安裝銀河麒麟V10系統(tǒng),配置gcc交叉編譯環(huán)境(鯤鵬服務(wù)器)

    VMware Workstation安裝銀河麒麟V10系統(tǒng),配置gcc交叉編譯環(huán)境(鯤鵬服務(wù)器)

    ? ? ? ?在一種計(jì)算機(jī)環(huán)境中運(yùn)行的編譯程序,能編譯出在另外一種環(huán)境下運(yùn)行的代碼,我們就稱這種編譯器支持交叉編譯。這個(gè)編譯過程就叫交叉編譯。簡單地說,就是在一個(gè)平臺上生成另一個(gè)平臺上的可執(zhí)行代碼。 ? ? ? 要進(jìn)行交叉編譯,我們需要在主機(jī)平臺上安裝對應(yīng)

    2024年02月04日
    瀏覽(38)
  • Win10 OpenCV編譯安裝CUDA版本

    Win10 OpenCV編譯安裝CUDA版本

    Win10 + Microsoft Visual Studio Community 2017 + CUDA11.3 + CUDNN8.2 + RTX GeForce 3090 + OpenCV4.5.3 前往官網(wǎng)下載Visual Studio Installer即可,做如下勾選,安裝即可 完成后,查看環(huán)境變量,將MSVC編譯器地址加入環(huán)境變量 前往官網(wǎng)下載CUDA和對應(yīng)的CUDNN,切記一定要對應(yīng)CUDNN和CUDA版本,根據(jù)提示一步一

    2024年02月06日
    瀏覽(34)
  • win10下wsl2使用記錄(系統(tǒng)遷移到D盤、配置國內(nèi)源、安裝conda環(huán)境、配置pip源、安裝pytorch-gpu環(huán)境、安裝paddle-gpu環(huán)境)

    win10下wsl2使用記錄(系統(tǒng)遷移到D盤、配置國內(nèi)源、安裝conda環(huán)境、配置pip源、安裝pytorch-gpu環(huán)境、安裝paddle-gpu環(huán)境)

    安裝好后環(huán)境測試效果如下,支持命令nvidia-smi,不支持命令nvcc,usr/local目錄下沒有cuda文件夾。 系統(tǒng)遷移到非C盤 wsl安裝的系統(tǒng)默認(rèn)在c盤,為節(jié)省c盤空間進(jìn)行遷移。 1、輸出 wsl -l 查看要遷移的系統(tǒng)名稱 2、執(zhí)行導(dǎo)出命令: wsl --export Ubuntu-20.04 ./Ubuntu-20.04.tar ,以下命令將系統(tǒng)

    2024年02月20日
    瀏覽(15)
  • windows10系統(tǒng)下安裝opencv4.7.0+VSCode+(C++)環(huán)境搭建

    windows10系統(tǒng)下安裝opencv4.7.0+VSCode+(C++)環(huán)境搭建

    windows10系統(tǒng)下安裝opencv4.7.0+VSCode+(C++)環(huán)境搭建 1.VScode最新版 2.Opencv:opencv-4.7.0、opencv_contrib-4.7.0(擴(kuò)展庫,可自選是否安裝) 3.MinGW-w64:選擇GCCWindows版本 4.c-make工具:最新版,應(yīng)選擇二進(jìn)制版本 注意 : (1)以上安裝包目錄文件中不應(yīng)包含空格空格和其他非法字符,否則后面會

    2023年04月10日
    瀏覽(24)
  • Win10編譯安裝openssl 1.1.1和 GPG

    Win10編譯安裝openssl 1.1.1和 GPG

    參考: openssl/NOTES-WINDOWS.md at master · openssl/openssl · GitHub 安裝Strawberry Perl Strawberry Perl for Windows 1.2 下載openssl源碼 下載 1.1.1u版本 /source/index.html 1.3 安裝NASM 下載NASM ,stable版本即可 https://www.nasm.us/ 1.4 安裝Microsoft Visual C compiler 因?yàn)檫@里本地機(jī)器裝過 Visual Studio 社區(qū)版, 所以需要

    2024年02月04日
    瀏覽(20)
  • 在win10上,配置 Rust 開發(fā)環(huán)境(使用 mingw64編譯器) 和 idea 配置 Rust 插件

    在win10上,配置 Rust 開發(fā)環(huán)境(使用 mingw64編譯器) 和 idea 配置 Rust 插件

    2.1、編譯器 mingw 與 visual studio 之間的選擇 Rust 底層是依賴C/C++的 編譯器,所以需要先安裝C/C++編譯環(huán)境。 Windows上C/C++ 的 編譯器 有兩種: 微軟 的 Visual Studio (msvc) GNU 的 Mingw (gnu): 官網(wǎng)地址:https://www.mingw-w64.org/ Rust 默認(rèn)使用的是 Visual Studio, 使用默認(rèn)選項(xiàng)就能安裝上,

    2024年02月02日
    瀏覽(18)
  • win10、win11下WSL2環(huán)境安裝

    win10、win11下WSL2環(huán)境安裝

    微軟官方wsl手冊 微軟官方wsl手冊pdf 打開win10的設(shè)置,搜索windows功能,打開啟用或者關(guān)閉Windows功能(win11可能搜不到,需要在控制面板里面搜索) 勾選以下2個(gè)地方,并重啟,也有可能是中文名字“虛擬機(jī)平臺” 下載WSL2升級包,并點(diǎn)擊安裝 WSL2升級包 以管理打開Powershell,并執(zhí)行

    2023年04月17日
    瀏覽(19)
  • Win10安裝Java 配置環(huán)境變量

    Win10安裝Java 配置環(huán)境變量

    學(xué)習(xí)java開發(fā)首先需要安裝jdk,并設(shè)置環(huán)境變量。 接下來就來介紹一下如何在 windows 10 系統(tǒng)中配置java環(huán)境變量 https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe 1. 雙擊安裝包打開 【JDK 安裝對話框】 2. 更改安裝目錄至D盤 1. 右鍵點(diǎn)擊 【我的電腦 - 屬性】,打開 【設(shè)置】 面

    2024年02月11日
    瀏覽(20)
  • jdk11下載、安裝及環(huán)境配置詳解(win10環(huán)境)

    jdk11下載、安裝及環(huán)境配置詳解(win10環(huán)境)

    1.1、官網(wǎng)下載網(wǎng)址 https://www.oracle.com/java/technologies/downloads/#java11-windows 1.2、官網(wǎng)下載步驟 點(diǎn)擊官網(wǎng)下載地址后,選擇對應(yīng)的系統(tǒng)環(huán)境,下載即可,如下圖: 下載好安裝包后,雙擊.exe程序,彈出如下窗口,點(diǎn)擊【下一步】 更改安裝目錄,點(diǎn)擊【下一步】,如下圖: 等待安裝,

    2024年01月15日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包