I faced similar issue in Conflict between libtorch and grpc
If I link only one among libtorch and grpc, it works. However, If I tried to link both at the same time, build failed.
/usr/bin/ld: CMakeFiles/server.dir/server.cc.o: in function `RunServer()': server.cc:(.text+0x139): undefined reference to `grpc::ServerBuilder::AddListeningPort(std::string const&, std::shared_ptr<grpc::ServerCredentials>, int*)' collect2: error: ld returned 1 exit status make: *** [CMakeFiles/server.dir/build.make:150: server] Error 1
Environment: Ubuntu 20.04 libtorch: 1.11.0+cpu gRPC: 1.50.0 ( And I tried 1.40, 1.38)
In previous issues which I linked, there was comment, *“Currently the easiest way is to compile libtorch with the protobuf library that grpc uses, or compile grpc with the protobuf library that libtorch uses”.
So I tried to install grpc with the protobuf library that libtorch uses. The process as follows,
# Install torch 1.11.0 wget https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.11.0%2Bcpu.zip unzip libtorch-shared-with-deps-1.11.0+cpu.zip && rm libtorch-shared-with-deps-1.11.0+cpu.zip # Install gRPC git clone -b v1.50.0 https://github.com/grpc/grpc cd grpc git submodule update --init cd third_party rm -r protobuf # remove protobuf and clone protobuf version 22.214.171.124 that libtorch uses git clone --recurse-submodules -b v126.96.36.199 --depth 1 --shallow-submodules https://github.com/protocolbuffers/protobuf.git mkdir -p cmake/build && \ cd cmake/build && \ cmake -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ -DCMAKE_INSTALL_PREFIX=/usr/local/grpc \ ../.. && \ make && \ make install && \ ldconfig
How can I resolve this problem??? Is it correct way to install protobuf that libtorch uses?