I'm trying to compile a library that depends on libevent. The library is part of a bigger project using cmake build system that has a top-level CMakeLists.txt file.
The CMakelists.txt file within the library directory contains
target_include_directories(<library name> PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
target_link_libraries(<library name> PUBLIC event)
libevent seems to be present on the system -
$ 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
So is event.h
$ ls -l /usr/include/event.h
-rw-r--r-- 1 root root 2744 Feb 5 2018 /usr/include/event.h
I also installed libevent-dev -
$ dpkg -l | grep libevent-dev
ii libevent-dev 2.1.8-stable-4build1 amd64 Asynchronous event notification library (development files)
I'm not sure why when I run make library, I get the following error -
fatal error: event.h: No such file or directory
#include <event.h>
Any suggestions would be helpful. Thanks!
You need to add path /usr/include to the list of include dirs.
target_include_directories(<library name> PRIVATE /usr/include ${CMAKE_CURRENT_SOURCE_DIR} ${SOME_DEP_DIR}/include)
UPDATE: A better approach is to use cmake's pkg-config module to find libraries that provide pkg-config's .pc file.
# 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})
The libevent.pc contains all the necessary information that is required to successfully link against the library libevent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With