linux下使用NetBeans调试libevent库
2013-03-17 17:18
225 查看
1.安装libevent
参考:/article/11177730.html
libevent安装在usr/local/libevent下
2.安装netBeans
http://www.netbeans.org
3.配置netBeans
1)打开项目的属性选项,选择包含目录,把/usr//local/libevent/include目录加进来
2) 链接器,在【其他库目录】把libevent的lib目录加上,在【库】中把要链接的库文件设为libevent/lib中的libevent.so即可。
3)运行程序
4)调试程序
可以跳入到libevent的代码下
5) 程序:
4.说明
如果是C语言选对应选项即可
原文参考:http://hi.baidu.com/492943457/item/ca73933c34698e27b3c0c528
参考:/article/11177730.html
libevent安装在usr/local/libevent下
2.安装netBeans
http://www.netbeans.org
3.配置netBeans
1)打开项目的属性选项,选择包含目录,把/usr//local/libevent/include目录加进来
2) 链接器,在【其他库目录】把libevent的lib目录加上,在【库】中把要链接的库文件设为libevent/lib中的libevent.so即可。
3)运行程序
4)调试程序
可以跳入到libevent的代码下
5) 程序:
#include <cstdlib> #include <stdio.h> #include <string.h> #include <time.h> #include <event2/event.h> #include <event2/event_struct.h> #include <unistd.h> using namespace std; #define N 300 #define BUFLEN 256 struct timeval lasttime; struct ST_EventWithDescription { struct event *p_event; int time_interval; char lable[BUFLEN]; }; static void timeout_cb(evutil_socket_t fd, short event, void *arg) { struct timeval newtime, difference; struct ST_EventWithDescription *pSTEvent = (ST_EventWithDescription*)arg; struct event *timeout = pSTEvent->p_event; double elapsed; evutil_gettimeofday(&newtime, NULL); evutil_timersub(&newtime, &lasttime, &difference); elapsed = difference.tv_sec + (difference.tv_usec / 1.0e6); printf("%s called at %d: %.3f seconds since my last work.\n", (char*)pSTEvent->lable,(int)newtime.tv_sec, elapsed); lasttime = newtime; struct timeval tv; evutil_timerclear(&tv); tv.tv_sec = pSTEvent->time_interval; event_add(timeout, &tv); } void setParam(struct ST_EventWithDescription *stEventDescription, struct event *m_event,int time_interval,char* m_lable) { stEventDescription->p_event = m_event; stEventDescription->time_interval = time_interval; memset(stEventDescription->lable,0,sizeof(stEventDescription->lable)); memcpy(stEventDescription->lable,m_lable,strlen(m_lable)+1); } void setTimeIntervalArr(int *arr,int n) { int i; srand(time(NULL)); for(i=0; i<n; ++i) { *(arr+i) = rand()%n + 1; //*(arr+i) = i+1; } } int main(int argc, char** argv) { struct event timeout ; struct ST_EventWithDescription stEvent ; int time_interval ; int i=0; struct timeval tv; struct event_base *base; int flags = 0; setTimeIntervalArr(time_interval,N); base = event_base_new(); evutil_timerclear(&tv); for(i=0; i<N; ++i) { char buf[BUFLEN]= {0}; sprintf(buf,"task%d",i+1); setParam(stEvent+i,timeout+i,time_interval[i],buf); event_assign(timeout+i, base, -1, flags, timeout_cb, (void*)(stEvent+i)); event_add(timeout+i, &tv); } evutil_gettimeofday(&lasttime, NULL); event_base_dispatch(base); return 0; }
4.说明
如果是C语言选对应选项即可
原文参考:http://hi.baidu.com/492943457/item/ca73933c34698e27b3c0c528
相关文章推荐
- linux下使用NetBeans调试libevent库
- Linux内核调试技术——jprobe使用与实现
- linux下core文件的调试(valgrind使用)
- linux之gdb基本调试命令和使用总结
- 使用NetBeans + Xdebug调试PHP程序的方法
- 【C语言】开发工具--Linux下调试工具GDB的使用
- 使用GDB调试Linux软件
- 使用 ftrace 调试 Linux 内核,第 2 部分
- Linux使用eclipse编译,调试Nginx模块
- 使用GDB调试Linux软件
- Linux中使用GDB调试NS2
- Android/Linux驱动开发之使用dev_dbg调试设备驱动
- 在Linux中使用VS Code编译调试C++项目(gcc/g++、Makefile入门、vs code)
- Linux调试工具GDB使用简易教程
- linux 中C语言便于调试的宏定义编写及 __FILE__,__FUNCTION__, __LINE__参数使用
- Winscp和Putty配合使用,远程调试linux
- 使用 ftrace 调试 Linux 内核
- Linux下使用addr2line调试程序的方法
- Linux下使用gdb进行单步调试(三)
- linux 使用ps,gdb调试程序