event.h: 即使安装了 libevent-dev 也没有这样的文件或目录
event.h: No such file or directory even when libevent-dev is installed
我正在尝试编译一个依赖于 libevent 的库。该库是使用 cmake 构建系统的更大项目的一部分,该系统具有顶级 CMakeLists.txt 文件。
库目录中的CMakelists.txt文件包含
target_include_directories(<library name> PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
target_link_libraries(<library name> PUBLIC event)
libevent 似乎存在于系统中 -
$ ldconfig -p | grep event
libtevent.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libtevent.so.0
libtevent-util.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libtevent-util.so.0
libevent_pthreads-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_pthreads-2.1.so.6
libevent_openssl-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_openssl-2.1.so.6
libevent_extra-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_extra-2.1.so.6
libevent_core-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
libevent-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
event.h
也是
$ ls -l /usr/include/event.h
-rw-r--r-- 1 root root 2744 Feb 5 2018 /usr/include/event.h
我还安装了 libevent-dev -
$ dpkg -l | grep libevent-dev
ii libevent-dev 2.1.8-stable-4build1 amd64 Asynchronous event notification library (development files)
我不确定为什么在 运行 make library
时出现以下错误 -
fatal error: event.h: No such file or directory
#include <event.h>
任何建议都会有所帮助。谢谢!
您需要将路径 /usr/include 添加到包含目录列表中。
target_include_directories(<library name> PRIVATE /usr/include ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
更新:更好的方法是使用 cmake 的 pkg-config 模块来查找提供 pkg-config 的 .pc 文件的库。
# Add pkg-config functionality
find_package(PkgConfig REQUIRED)
# search for libevent.pc
pkg_search_module(EVENT REQUIRED libevent)
target_include_directories(<library name> PRIVATE ${EVENT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
target_link_libraries(<library name> PUBLIC ${EVENT_LIBRARIES})
libevent.pc 包含成功 link 库 libevent 所需的所有必要信息。
我正在尝试编译一个依赖于 libevent 的库。该库是使用 cmake 构建系统的更大项目的一部分,该系统具有顶级 CMakeLists.txt 文件。
库目录中的CMakelists.txt文件包含
target_include_directories(<library name> PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
target_link_libraries(<library name> PUBLIC event)
libevent 似乎存在于系统中 -
$ ldconfig -p | grep event
libtevent.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libtevent.so.0
libtevent-util.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libtevent-util.so.0
libevent_pthreads-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_pthreads-2.1.so.6
libevent_openssl-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_openssl-2.1.so.6
libevent_extra-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_extra-2.1.so.6
libevent_core-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
libevent-2.1.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
event.h
也是$ ls -l /usr/include/event.h
-rw-r--r-- 1 root root 2744 Feb 5 2018 /usr/include/event.h
我还安装了 libevent-dev -
$ dpkg -l | grep libevent-dev
ii libevent-dev 2.1.8-stable-4build1 amd64 Asynchronous event notification library (development files)
我不确定为什么在 运行 make library
时出现以下错误 -
fatal error: event.h: No such file or directory
#include <event.h>
任何建议都会有所帮助。谢谢!
您需要将路径 /usr/include 添加到包含目录列表中。
target_include_directories(<library name> PRIVATE /usr/include ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
更新:更好的方法是使用 cmake 的 pkg-config 模块来查找提供 pkg-config 的 .pc 文件的库。
# Add pkg-config functionality
find_package(PkgConfig REQUIRED)
# search for libevent.pc
pkg_search_module(EVENT REQUIRED libevent)
target_include_directories(<library name> PRIVATE ${EVENT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
target_link_libraries(<library name> PUBLIC ${EVENT_LIBRARIES})
libevent.pc 包含成功 link 库 libevent 所需的所有必要信息。