I am trying to build and run the grpc examples with grpc that was installed with vcpkg manager.
I installed vcpkg manager by cloning and finding grpc like so:
sudo apt-get install -y unzip build-essential
git clone https://github.com/microsoft/vcpkg
cd vcpkg/
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg search grpc
./vcpkg install grpc
export PATH=$PATH:$HOME/vcpkg/downloads/tools/cmake-3.14.0-linux/cmake-3.14.0-Linux-x86_64/bin
Great! So I think I have grpc. I also needed protobuf but it came installed with vcpkg's grpc. If I try to install protobuf I get the following output:
an@ubuntu:~/vcpkg$ ./vcpkg install protobuf
Computing installation plan...
The following packages are already installed:
protobuf[core]:x64-linux
Package protobuf:x64-linux is already installed
Total elapsed time: 205.3 us
The package protobuf:x64-linux provides CMake targets:
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite
To double check I use ./vcpkg list
to show all the packages I have installed. Heres what it looks like. Note: protobuf and grpc
adrian@ubuntu:~/vcpkg$ ./vcpkg list
abseil:x64-linux 2020-03-03#8 an open-source collection designed to augment th...
c-ares:x64-linux 2019-5-2-1 A C library for asynchronous DNS requests
grpc:x64-linux 1.31.1 An RPC library and framework
openssl-unix:x64-linux 1.1.1h OpenSSL is an open source project that provides ...
openssl:x64-linux 1.1.1g#1 OpenSSL is an open source project that provides ...
protobuf:x64-linux 3.13.0#2 Protocol Buffers - Google's data interchange format
re2:x64-linux 2020-10-01 RE2 is a fast, safe, thread-friendly alternative...
upb:x64-linux 2020-08-19 μpb (often written 'upb') is a small protobuf i...
zlib:x64-linux 1.2.11#9 A compression library
We can also see grpc and protobuf's binarys in the /vcpkg/installed/x64-linux/libs
directory highlighted below:
Ok great! So now I want to try and compile grpc's hello world examples with the vcpkg manager plugins. In the official grpc website they have a quick instructions for building then compiling. (by default they install grpc natively but its a mess uninstall which is why I went with vcpkg instead).So lets try to compile with these instructions from grpc's quick start guide:
mkdir -p cmake/build
pushd cmake/build
cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
make -j
Its important to note that at the beginning they installed grpc natively (which is messy to remove unliked vcpkg). Their instructions indicate to set MY_INSTALL_DIR
like so:
export MY_INSTALL_DIR=$HOME/.local
export PATH="$PATH:$MY_INSTALL_DIR/bin"
But this is for installing and compiling grpc's binaries natively. Unfortunately I dont know where the binaries are for vckpkg manager. I see that cmake installs and has a binary located at: vcpkg/downloads/tools
but I do not see grpc or protobuf folder for their respecive binaries (see image below). Where would the binaries be located for vcpkg? Per grpc's official instructions I am supposed to use cmake and define these below.
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
Unfortunately I am relatively new to vcpkg and dependencies with a little experience using Makefiles (which i believe are much different than cmake/cmakelists. I never made cmake files from scratch as I primarily use Makefiles). Could someone please point me in the right direction how to compile and run these examples with vcpkg (or suggest a better approach?) My goal is to learn how to use vcpkg and integrate it into an existing project like gRPC's example files.
Update 1:
I cd to the example hellow world folder and ran the following as suggested:
mkdir build-dir
cd build-dir
cmake ..
make
When I ran cmake ..
I got the following error:
grpc/examples/cpp/helloworld/build$ cmake ..
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
Call Stack (most recent call first):
CMakeLists.txt:24 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
This was an indicator that I am not using the correct cmake (the one used by vcpkg. So i did a little digging and according to this vcpkg documentation I need to integrate vcpkg packages with ./vcpkg integrate install
which exposes all my packages on my system as long as I point it to the cmake within. It then says I should seed a path:
~/vcpkg$ ./vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake"
So I try to build with cmake ..
but instead I provide the DCMAKE_TOOL_CHAIN
argument like so but I am back to the original problem as before.
/grpc/examples/cpp/helloworld/build$ cmake .. "-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake"
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
Call Stack (most recent call first):
CMakeLists.txt:24 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!