【问题标题】:Cmake - Unable to found gRPC library on MacOSCmake - 无法在 MacOS 上找到 gRPC 库
【发布时间】:2022-07-23 12:50:46
【问题描述】:

我正在尝试在我的 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.

知道我的错误在哪里,我怎样才能使这个工作正常?

【问题讨论】:

  • 根据错误信息,您的机器上没有安装 Abseil 包。

标签: c++ cmake grpc


【解决方案1】:

这看起来是 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 2014-08-02
    • 2014-08-02
    • 2021-07-14
    • 1970-01-01
    相关资源
    最近更新 更多