Unexpected path to libprotocd.lib after add gRPC::grpc++ library dependence in CMake

你离开我真会死。 提交于 2020-01-25 00:25:11

问题


I have a gRPC 1.23.0 compiled by conan(and all dependencies also resolved by conan). And I have a CMake project, that use grpc library:

set (LIB_DEPS
  protobuf::libprotobuf
  gRPC::grpc++
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})

When I generate a VS project from this CMakeLists.txt in Linker - Input - Addition Dependencies property, I have there next value:

C:\.conan\data\protobuf\3.9.1\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\libprotobufd.lib <-- (1)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc++.lib
libprotocd.lib   <-- (2)
libprotobufd.lib  <-- (3)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\gpr.lib
C:\.conan\data\c-ares\1.15.0\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\cares.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\address_sorting.lib
wsock32.lib
kernel32.lib

(1) - expected valid path, that I add in CMakeLists.txt

(2),(3) - unexpected and invalid path, that added by gRPC::grpc++ in CMakeLists.txt. If I change gRPC::grpc++ to gRPC::grpc, lines (2) and (3) will disappear, but path to grpc++.lib will disappear too, but I need it.

How to avoid this strange invalid path to libprotocd.lib and libprotobufd.lib?


回答1:


To properly link against grpc targets you can use:

target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::grpc)

This should contain everything required. More details on this approach here: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach




回答2:


I have found workaround solution:

find_library(GRPC_GRPC++_LIBRARY NAMES grpc++)
set (LIB_DEPS
  protobuf::libprotobuf
  gRPC::grpc
  ${GRPC_GRPC++_LIBRARY NAMES}
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})

And opened the issue about it in gRPC repository: https://github.com/grpc/grpc/issues/20578



来源:https://stackoverflow.com/questions/58325828/unexpected-path-to-libprotocd-lib-after-add-grpcgrpc-library-dependence-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!