CMake 在 macOS 上找不到 libevent

Posted

技术标签:

【中文标题】CMake 在 macOS 上找不到 libevent【英文标题】:CMake can't find libevent on macOS 【发布时间】:2019-06-03 07:25:23 【问题描述】:

我已经在 macOS 上安装了 libevent -

$ brew install libevent

我正在尝试将其导入我的 CMakeLists.txt -

cmake_minimum_required(VERSION 3.14)
project(xyz)
set(CMAKE_CXX_STANDARD 17)
find_package(libevent REQUIRED)

我收到以下 CMake 错误 -

CMake Error at CMakeLists.txt:6 (find_package):
  By not providing "Findlibevent.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "libevent",
  but CMake did not find one.

  Could not find a package configuration file provided by "libevent" with any
  of the following names:

    libeventConfig.cmake
    libevent-config.cmake

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

有人能告诉我如何在 CMake 中导入安装在系统中的 libevent 吗?

【问题讨论】:

【参考方案1】:

我有同样的问题,但我通过添加以下内容来解决这个问题:

link_directories(
  /usr/local/lib
  /usr/lib
)
INCLUDE_DIRECTORIES(
  /usr/local/include/
  /usr/include
)

它只是告诉 Makefile 在哪里可以找到 libevent 头文件和库。

【讨论】:

以上是关于CMake 在 macOS 上找不到 libevent的主要内容,如果未能解决你的问题,请参考以下文章

在 macOS 11.3 上找不到“gl.h”

在 MacOS Sierra 上找不到 OpenSSL

jenv 在 MacOS 上找不到通过 brew 安装的 java 17

在 MacOs Mojave 上找不到 XAMPP 的 httpd-xampp.conf 文件

在 Mac OS 上找不到 /dev/kvm

QtCreator 找不到 cmake