我正在尝试使用g ++链接libevent,但由于我在配置时使用--prefix标志设置了libevent的安装目录,因此遇到了麻烦。要安装libevent,我下载了最新的源代码,将其解压缩并在目录
中运行以下命令./configure --prefix=/home/tom/local --disable-shared && make make install
运行这些命令后,libevent成功安装到/ home / tom / local文件夹。现在测试我可以使用libevent我已经下载了带有libevent的示例rot13服务器,可以找到底部:http://www.wangafu.net/~nickm/libevent-book/01_intro.html
要编译我运行以下命令:
g++ -I=/home/tom/local/include rot13server.cpp -L/home/tom/local/lib
但是我收到以下编译错误:
/tmp/cctwJY4k.o: In function `alloc_fd_state(event_base*, int)': libevent.cc:(.text+0x9b): undefined reference to `event_new' libevent.cc:(.text+0xec): undefined reference to `event_new' libevent.cc:(.text+0x11a): undefined reference to `event_free' /tmp/cctwJY4k.o: In function `free_fd_state(fd_state*)': libevent.cc:(.text+0x1b6): undefined reference to `event_free' libevent.cc:(.text+0x1c9): undefined reference to `event_free' /tmp/cctwJY4k.o: In function `do_read(int, short, void*)': libevent.cc:(.text+0x310): undefined reference to `event_add' /tmp/cctwJY4k.o: In function `do_write(int, short, void*)': libevent.cc:(.text+0x4da): undefined reference to `event_del' /tmp/cctwJY4k.o: In function `do_accept(int, short, void*)': libevent.cc:(.text+0x564): undefined reference to `evutil_make_socket_nonblocking' libevent.cc:(.text+0x5da): undefined reference to `event_add' /tmp/cctwJY4k.o: In function `run()': libevent.cc:(.text+0x5f3): undefined reference to `event_base_new' libevent.cc:(.text+0x63f): undefined reference to `evutil_make_socket_nonblocking' libevent.cc:(.text+0x6d2): undefined reference to `event_new' libevent.cc:(.text+0x6e7): undefined reference to `event_add' libevent.cc:(.text+0x6f3): undefined reference to `event_base_dispatch' collect2: error: ld returned 1 exit status
似乎编译器正在查找包含文件而不是目标文件。
我还尝试在没有--disable-shared选项的情况下配置libevent,然后将/ home / tom / local / lib导出到LD_LIBRARY_PATH但是我仍然遇到与compile命令相同的错误:
g++ -I=/home/tom/local/include rot13server.cpp谁能告诉我我做错了什么? 感谢
答案 0 :(得分:0)
谁能告诉我我做错了什么?
关于一切。
-I=/home/tom/local/include
告诉GCC查看=/home/tom/local/include
目录,该目录不太可能存在。
你想:
g++ -I/home/tom/local/include rot13server.cpp -c
g++ -L/home/tom/local/lib rot13server.o -levent -o rot13server