Linux libevent Compiling & testing __linux

Source: Internet
Author: User
1. Download
http://download.csdn.net/detail/sauphy/9314091


2. Compile
./configure--prefix=/opt/libevent
Make
Make install


3. Develop and compile
GCC Test_signal.c-o ok-i/opt/libevent/include-l/opt/libevent/lib-levent
./ok


3-1, connection error:
Error while loading shared libraries:
Libevent-2.0.so.5:cannot open Shared object file:no such file or directory
A1,
Ln-s/opt/libevent/lib/libevent-2.0.so.5/usr/lib64/libevent-2.0.so.5


4. Run
./ok

CTRL + C run (show two signals)


===============================

#include <sys/types.h> #include <event2/event-config.h> #include <sys/stat.h> #ifndef WIN32 #include <sys/queue.h> #include <unistd.h> #include <sys/time.h> #else #include <winsock2.h> #include <windows.h> #endif #include <signal.h> #include <fcntl.h> #include <stdlib.h> #include < stdio.h> #include <string.h> #include <errno.h> #include <event.h> #ifdef _event___func__ #define _

_func__ _event___func__ #endif int called = 0;

	static void Signal_cb (evutil_socket_t fd, short event, void *arg) {struct event *signal = arg;

	printf ("%s:got signal%d\n", __func__, Event_signal (signal));

	if (called >= 2) Event_del (signal);
called++;
	int main (int argc, char **argv) {struct event signal_int;
struct event_base* base;
	#ifdef WIN32 WORD wversionrequested;

	Wsadata Wsadata;

	wversionrequested = Makeword (2, 2); (void)
WSAStartup (wversionrequested, &wsadata); #endif/* Initalize tHe event Library */base = Event_base_new (); /* Initalize One event */event_assign (&signal_int, Base, SIGINT, ev_signal|

	Ev_persist, SIGNAL_CB, &signal_int);

	Event_add (&signal_int, NULL);
	Event_base_dispatch (base);

	Event_base_free (base);
return (0); }

================

CC       = gcc
CXX      = g++
Ld_flag  =-G
LIBS     =-l/opt/libevent/lib-levent INCLUDES
=-i/opt/ Libevent/include

TARGET = OK

${target}:
        $ (CC) Main.c $ (ld_flag) $ (LIBS) $ (INCLUDES)-O  $ (TARGET) Clean 
:
        rm-rf *.o *~ $ (TARGET)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.