【问题标题】:How to solve compile error in gRPC generated files?如何解决 gRPC 生成文件中的编译错误?
【发布时间】:2019-07-10 12:58:19
【问题描述】:

我正在使用 gRPC 创建客户端-服务器应用程序。到目前为止,我没有使用 TLS 加密。现在我想启用它,奇怪的是我得到了这个错误。至少在我看来,这是一个链接器错误。解决它的最佳方法是什么? CLion 没有突出显示任何内容,所以我认为一切在语法上都没有问题,但是在编译时我得到了那个错误。

/usr/bin/ld: CMakeFiles/projectname.dir/main.cpp.o: in function `grpc::SslServerCredentials(grpc::SslServerCredentialsOptions const&)':
/home/username/projectname/third_party/grpc/include/grpcpp/security/server_credentials.h:60: undefined reference to `grpc_impl::SslServerCredentials(grpc::SslServerCredentialsOptions const&)'
collect2: error: ld returned 1 exit status

这是我用来从 gRPC 规范生成 C++ 代码的 makefile:

HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
CPPFLAGS += `pkg-config --cflags protobuf grpc`
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\
           -lgrpc++_reflection\
           -ldl
else
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\
           -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
           -ldl
endif
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`

PROTOS_PATH = ./

vpath %.proto $(PROTOS_PATH)

%.grpc.pb.cc: %.proto
    $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<

%.pb.cc: %.proto
    $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<

clean:
    rm -f *.o *.pb.cc *.pb.h

【问题讨论】:

  • 能否请您提供用于生成 protbuf/gRPC 代码的命令?
  • 我添加了一个makefile,这是你要的吗?

标签: c++ cmake grpc


【解决方案1】:

然后问题就这样解决了: 我不得不在CMakeLists.txt cmake 构建配置文件中将grpc++_unsecure 下的grpc++ 更改为grpc++。 我一开始忘记/没有想到这一点。

target_link_libraries(bita_server
        pqxx
        sodium
        protobuf::libprotobuf
#        grpc++_unsecure
        grpc++
        SQLiteCpp
        sqlite3
        pthread
        dl
        ${_PROTOBUF_LIBPROTOBUF}
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 2019-09-04
    • 2013-03-17
    • 1970-01-01
    • 2017-08-15
    • 2013-03-29
    • 1970-01-01
    相关资源
    最近更新 更多