【发布时间】:2019-12-25 22:34:59
【问题描述】:
当我尝试在文件夹 grpc/examples/cpp/helloworld 中运行用于 c++ 的 gRPC 示例时,它需要在我使用 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$||'`;\
只有两行
【问题讨论】:
-
"但只有 C 库" - 你怎么知道那些是 C 库?其次,为什么它们是 C 库会成为问题? C++ 代码可以使用大多数(几乎所有)C 库。
-
我的意思是在 grpc/libs/opt 中必须至少有 libgrpc++.a、libgrpc++.so、libgrpc++_unsecure.a 和 libgrpc++_unsecure.so 的库。但我没有在这个文件夹中。
-
是的,应该有一个
libgrpc++.so和一个libgrpc++_reflection.so被构建。