通过上一节《Linux下编译libevent源码》后,我们在/usr/local/include和/usr/local/lib已经可以分别看到libevent的头文件和库文件了
在libevent解压后的源码目录的sample目录中,存放着官方提供的例子。
我们以里面的hello-world.c为例讲解libevent在linux下开发环境的搭建。
把hello-world.c拷贝到我们工程目录
编译:
gcc hello-world.c -o main -levent
如果遇到报错:error while loading shared libraries:libevent.XXX:cannot open shared object file:no such file or directory
在 /etc/ld.so.conf.d里面加上/usr/local/lib
sudo ldconfig
然后就可以运行我们编译出来的程序了