当我试图在文件夹gRPC / c++ /cpp/helloworld中运行c++示例时,它需要在用Cmake构建gRPC时没有编译的库。
首先,我在Ububtu16.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/libs/opt/pkgconfig/ grpc++_unsecure.pc复制到/usr/local/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 / 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编译静态和动态库。是我做错了什么,还是没做什么,还是有错误?原型机的版本是
:~$ 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$||'`;\只有两行
发布于 2019-08-21 16:02:23
所以我解决了这个问题。当我在根gRPC文件夹上运行"make“时,编译以以下结果结束:
[CXX] Compiling /home/user/cpp_test/grps/grpc/gens/src/proto/grpc/core/stats.pb.cc
/home/user/cpp_test/grps/grpc/gens/src/proto/grpc/core/stats.pb.cc:187:13: error: ‘dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto’ defined but not used [-Werror=unused-variable]
static bool dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto = []()
^
cc1plus: all warnings being treated as errors
Makefile:2924: recipe for target '/home/user/cpp_test/grps/grpc/objs/opt//home/user/cpp_test/august/grpc/gens/src/proto/grpc/core/stats.pb.o' failed
make: *** [/home/user/cpp_test/grps/grpc/objs/opt//home/user/cpp_test/august/grpc/gens/src/proto/grpc/core/stats.pb.o] Error 1 因为所有警告都被视为错误。并停止了另一个库的编译。因此,我在357行的末尾手动添加了gRPC根目录标志-Wno-unused-variable中的Makefile。在添加了这个gRPC库标志之后,成功地构建了所有的libgrpc++*和libgrpc*库。
CPPFLAGS += -g -Wall -Wextra -Werror $(W_NO_UNKNOWN_WARNING_OPTION) -Wno-long-long -Wno-unused-parameter -Wno-deprecated-declarations -Wno-sign-conversion -Wno-shadow -Wno-conversion -Wno-implicit-fallthrough -Wno-sign-compare -Wno-missing-field-initializers -Wno-maybe-uninitialized -DPB_FIELD_32BIT -DOSATOMIC_USE_INLINED=1 -Ithird_party/nanopb -Ithird_party/upb -Isrc/core/ext/upb-generated -Wno-unused-variablehttps://stackoverflow.com/questions/57578214
复制相似问题