2022年3月15日 星期二

C++ libevent with CMake 2022

http://senlinzhan.github.io/2017/08/12/libevent/
http://man6.org/blog/Libevent/CMake%E7%BC%96%E8%AF%91Libevent.md


libevent-2.1.8

$ wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
$ tar -xzvf libevent-2.1.8-stable.tar.gz
$ cd libevent-2.1.8-stable
$ ./configure
$ make
$ sudo make install


CMakeList.txt

cmake_minimum_required(VERSION 3.10)
project(alligator)

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

add_executable(alligator a.cpp)
target_link_libraries(alligator event)


c.app

#include <event2/event.h>
#include <iostream>
#include <string>
void timer_cb(evutil_socket_t fd, short what, void *arg)
{
    auto str = static_cast<std::string *>(arg);
    std::cout << *str << std::endl;
}
int main()
{
    std::string str = "Hello, World!";
    auto *base = event_base_new();
    struct timeval five_seconds = {1, 0};
    auto *ev = event_new(base, -1, EV_TIMEOUT, timer_cb, (void *)&str);
    event_add(ev, &five_seconds);
    event_base_dispatch(base);
    event_free(ev);
    event_base_free(base);
    return 0;
}


Ends

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...