2

I install grpc by vcpkg install grpc and add it to cmake file . Now I want to generate grpc c++ file , I run :

protoc --cpp_out=grpc_file/ --grpc_out=grpc_file/  --proto_path=grpc_proto/  ./grpc_proto/side_information.proto

It returns error :

protoc-gen-grpc: program not found or is not executable
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.

What should I do to use the grpc_cpp_plugin installed by vcpkg ? My workspace is :

.
├── CMakeLists.txt
├── Readme.md
├── build
├── build_envs.sh
├── grpc_file
├── grpc_proto
├── main.cpp
├── twitter.json
└── vcpkg
DachuanZhao
  • 1,181
  • 3
  • 15
  • 34
  • I understand that this is not the answer you are looking for, but please try bazel/cmake https://github.com/grpc/grpc/tree/master/src/cpp#grpc-c if you are having trouble with vcpkg. Bazel/CMake is what the gRPC devs use – Yash Tibrewal Mar 10 '21 at 21:19
  • Have you checked https://stackoverflow.com/questions/64404450/compile-grpc-c-examples-with-vcpkg It's not same, but might help you to see if you are missing some packages – jordanvrtanoski Mar 11 '21 at 08:40
  • Can you also show your configuration in CMake – jester Mar 11 '21 at 10:36
  • @DachuanZhao Was my answer helpful, or do you need more help? – Rane Mar 18 '21 at 00:51

2 Answers2

4

The protoc is trying to look for the protoc-gen-grpc plugin from your PATH, but it is unable to find one, thus the error. The fix is to simply specify the path to the said plugin. Given that you are using vcpkg, that path is probably something along these lines:

protoc --cpp_out=grpc_file/ --grpc_out=grpc_file/ --proto_path=grpc_proto/ \
--plugin=protoc-gen-grpc="<vcpkg_install_path>\packages\grpc_x64-windows\tools\grpc\grpc_cpp_plugin.exe" \ 
./grpc_proto/side_information.proto 

If you are looking to be using Visual Studio for your grpc project, I recommend checking out this guide for generating a VS solution among other things.

Rane
  • 321
  • 2
  • 6
1

Is your CMakeLists.txt like below?

cmake_minimum_required(VERSION 3.1)

if(DEFINED ENV{VCPKG_ROOT})
    set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
else()
    set(CMAKE_TOOLCHAIN_FILE "/path_to_vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()

project(Foo)

find_package(gRPC CONFIG REQUIRED)

...

add_executable(${PROJECT_NAME} ${Bar})

target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet)

In the Folder path_to_vcpkg/packages/grpc_x64-PLATFORM/tools/grpc you will find all the precompiled grpc-plugins for your platform (also grpc_cpp_plugin).

  • Like this . My CMakeLists.txt contains ```set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")``` . I find it . Thanks~ – DachuanZhao Mar 18 '21 at 01:57