CMake -在macOS上找不到gRPC库

ybzsozfc  于 8个月前  发布在  Mac
关注(0)|答案(2)|浏览(164)

我正在尝试在Mac M1上使用grpc,我遵循了以下指南:https://grpc.io/docs/languages/cpp/quickstart/
在我的项目CmakeLists.txt中,我有:

find_package(gRPC CONFIG REQUIRED)

当我尝试运行cmake时,我得到这个错误:

-- Could NOT find absl (missing: absl_DIR)
CMake Error at CMakeLists.txt:80 (find_package):
  Found package configuration file:

    /Users/venelin/.local/lib/cmake/grpc/gRPCConfig.cmake

  but it set gRPC_FOUND to FALSE so package "gRPC" is considered to be NOT
  FOUND.  Reason given by package:

  The following imported targets are referenced, but are missing: absl::base
  absl::core_headers absl::memory absl::random_random absl::status absl::cord
  absl::str_format absl::strings absl::synchronization absl::time
  absl::optional absl::flat_hash_map absl::inlined_vector absl::bind_front
  absl::hash absl::statusor absl::variant absl::utility protobuf::libprotobuf
  protobuf::libprotoc

所以我决定这样做:

find_package(absl CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)

但我得到了这个错误

CMake Error at CMakeLists.txt:80 (find_package):
  Could not find a package configuration file provided by "absl" with any of
  the following names:

    abslConfig.cmake
    absl-config.cmake

  Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
  "absl_DIR" to a directory containing one of the above files.  If "absl"
  provides a separate development package or SDK, be sure it has been
  installed.

你知道我的错误在哪里吗?我怎么才能做到这一点?

s1ag04yj

s1ag04yj1#

这看起来是一个OSX-M1特定的情况,最有可能通过真正遵循您获得的错误消息来解决:
将安装前缀“absl”添加到CMAKE_PREFIX_PATH
最有可能的是,你通过brew install Abseil安装了abs,它将它定位到/opt/homebrew/...中。请注意,cmake还没有在那里查找,它习惯于在明显的Unix/Linux位置(如/usr/local等)中查找内容。
因此,找到absl-config.cmake(例如,浏览或最坏情况下使用find / -name absl-config.cmake),并通过

list(APPEND CMAKE_PREFIX_PATH "/the/path/to/the/cmake-config/")

很可能是

list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew/opt/absl/include") #not sure about this one
find_package(absl CONFIG REQUIRED)

此外,一般来说,您应该设置包含和链接目录

link_directories("/opt/homebrew/lib")
include_directories("/opt/homebrew/include")

检查this post

wfypjpf4

wfypjpf42#

您不需要显式地将abseil添加到项目中。
在您的CMakeLists.txt中,您还必须包含Protobuf

find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)

确保在CONFIG模式下查找Protobuf,因为它的查找模块不包括absl,因此会导致很多麻烦。
找理由?对protobuf-config.cmakeFindProtobuf.cmake运行diff,输出如下:

8,9c346,372
< if(NOT TARGET absl::strings)
<   find_package(absl CONFIG)
---
> 
> 
> # Backwards compatibility
> # Define camel case versions of input variables
> foreach(UPPER
>     PROTOBUF_SRC_ROOT_FOLDER
>     PROTOBUF_IMPORT_DIRS
>     PROTOBUF_DEBUG
...

相关问题