当我尝试在文件夹 grpc/examples/cpp/helloworld 中运行 gRPC for c++ 示例时,它需要在我使用 Cmake 构建 gRPC 时未编译的库
首先,我按照说明在 Ububtu 16.04 中构建了 gRPC:
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
$ cd grpc
$ git submodule update --init
$ cd third_party/protobuf
$ git submodule update --init --recursive
$ ./autogen.sh
$ ./configure --prefix=/usr
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.
$ pkg-config --cflags protobuf # print compiler flags
$ pkg-config --libs protobuf # print linker flags
$ pkg-config --cflags --libs protobuf # print both
cd ../..
make
sudo make install
之后我尝试在文件夹 grpc/examples/cpp/helloworld 中运行示例
grps/grpc/examples/cpp/helloworld$ make
我有几个错误,通过将 grpc_cpp_plugin 从文件夹 grpc/bins/opt 复制到/usr/local/bin 以及将 grpc++.pc 和 grpc++_unsecure.pc 从 grpc/libs/opt/pkgconfig/复制到/usr/本地/lib/pkgconfig。 当我尝试下一次命令时
grpc/examples/cpp/helloworld$ make
我有消息
g++ helloworld.pb.o helloworld.grpc.pb.o greeter_client.o -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc` -pthread -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl -o greeter_client
/usr/bin/ld: cannot find -lgrpc++
/usr/bin/ld: cannot find -lgrpc++_reflection
collect2: error: ld returned 1 exit status
Makefile:44: recipe for target 'greeter_client' failed
make: *** [greeter_client] Error 1
所以,我在文件夹 grpc/libs/opt 中搜索了这些库 libgrpc++,但只有这些库
grpc/libs/opt$ ls --l
libaddress_sorting.a libgrpc_cronet.so.8
libaddress_sorting.so libgrpc_cronet.so.8.0.0
libaddress_sorting.so.8 libgrpc_plugin_support.a
libaddress_sorting.so.8.0.0 libgrpc.so
libares.a libgrpc.so.8
libboringssl.a libgrpc.so.8.0.0
libgpr.a libgrpc_unsecure.a
libgpr.so libgrpc_unsecure.so
libgpr.so.8 libgrpc_unsecure.so.8
libgpr.so.8.0.0 libgrpc_unsecure.so.8.0.0
libgrpc.a pkgconfig
libgrpc_cronet.a protobuf
libgrpc_cronet.so
所以make没有为gRPC编译静态库和动态库。是我做错了什么,还是什么都没做,还是有错误? protobuf的版本是
:~$ protoc --version
libprotoc 3.8.0
:~$ which protoc
/usr/bin/protoc
这是我从根目录运行“make”后的一些输出
[MAKE] Generating /home/user/cpp_test/grps/grpc/libs/opt/pkgconfig/grpc++.pc
[MAKE] Generating /home/user/cpp_test/grps/grpc/libs/opt/pkgconfig/grpc++_unsecure.pc
因此它为“libgrpc++*”库创建 pkgconfig 文件,但不创建这些库。
这些有 libgrpc++
libgrpc++ depbase=`echo google/protobuf/io/tokenizer.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
和
libgrpc++ depbase=`echo google/protobuf/util/delimited_message_util.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
只有两行
最佳答案
看起来你只从 third_party/protobuf
目录运行了 make
(第一步你需要这样做),然后运行了 make
从 helloworld
目录。如果您还没有这样做,您应该根据 documentation 从 grpc 存储库 root 目录运行 make
.这将确保构建 libgrpc++*
C++ 库。
关于c++ - gRPC 不会在 ubuntu 上为 c++ 生成库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57578214/