【问题标题】:Cannot link against grpc conan无法链接到 grpc 柯南
【发布时间】:2021-05-19 12:23:41
【问题描述】:

我尝试构建默认的 hello world (https://github.com/grpc/grpc/tree/master/examples/cpp/helloworld) grpc 示例,但使用的是 conan grpc。 我重新设计了 cmakelists:

# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# cmake build file for C++ helloworld example.
# Assumes protobuf and gRPC have been installed using cmake.
# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build
# that automatically builds all the dependencies before building helloworld.

cmake_minimum_required(VERSION 3.13)

project(HelloWorld C CXX)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/conanbuildinfo.cmake)

conan_basic_setup(TARGETS)

find_package(Protobuf REQUIRED)
#find_package(CONAN_PKG::grpc REQUIRED)
# Proto file
get_filename_component(hw_proto "../../protos/helloworld.proto" NAME        )
get_filename_component(hw_proto_path "${hw_proto}" PATH)
# Generated sources grpc_cpp_plugin

# Add Library target with protobuf sources
add_library(hw_grpc_proto ${hw_proto} ${hw_grpc_srcs} ${hw_grpc_hdrs})
message(STATUS plugins ${CONAN_BIN_DIRS_GRPC})
message(STATUS proto ${hw_proto})
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h")
set(hw_grpc_proto_PROTOS ${hw_proto})
set(grpc_cpp_plugin_location ${CONAN_BIN_DIRS_GRPC}/grpc_cpp_plugin)
message(STATUS grpc-plugin ${grpc_cpp_plugin_location})
protobuf_generate(TARGET hw_grpc_proto LANGUAGE cpp ${hw_proto_srcs} ${hw_proto_hdrs})
#protobuf_generate(TARGET hw_grpc_proto LANGUAGE grpc GENERATE_EXTENSIONS ${hw_grpc_srcs} ${hw_grpc_hdrs} PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")

message(STATUS ${Protobuf_PROTOC_EXECUTABLE})
add_custom_command(
      OUTPUT "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
      COMMAND ${Protobuf_PROTOC_EXECUTABLE}
      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
        -I "${hw_proto_path}"
        --plugin=protoc-gen-grpc="${grpc_cpp_plugin_location}"
        "${hw_proto}"
      DEPENDS "${hw_proto}")

# Include generated *.pb.h files


# hw_grpc_proto

target_link_libraries(hw_grpc_proto
  CONAN_PKG::grpc
  CONAN_PKG::protobuf
  )

# Targets greeter_[async_](client|server)
foreach(_target
  greeter_client greeter_server
  greeter_async_client greeter_async_client2 greeter_async_server)
  add_executable(${_target} "${_target}.cc")
  target_link_libraries(${_target}
    CONAN_PKG::grpc
    CONAN_PKG::protobuf
    hw_grpc_proto
    )
endforeach()

hw_grpc_proto 已构建,但在链接可执行文件时失败。 https://pastebin.com/3udDc68a(此处限制为 30k 个符号)

我使用带有此选项的柯南包

[settings]
    arch=x86_64
    build_type=Release
    compiler=gcc
    compiler.libcxx=libstdc++
    compiler.version=8
    os=Linux

在我的 debian buster 上使用 gcc 8.3.0 和 libstdc++6 我看到它必须链接到 protobuf 和 grpc 但它失败了。

【问题讨论】:

    标签: c++ grpc


    【解决方案1】:

    这里是答案https://stackoverflow.com/a/30175210/8524139 我真的不知道为什么柯南包含旧 gcc 的 protobuf 并且没有关于此的信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-31
      • 2022-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多